diff options
Diffstat (limited to '@linaria/packages/core')
-rw-r--r-- | @linaria/packages/core/CHANGELOG.md | 27 | ||||
-rw-r--r-- | @linaria/packages/core/README.md | 35 | ||||
-rw-r--r-- | @linaria/packages/core/__tests__/cx.test.ts | 7 | ||||
-rw-r--r-- | @linaria/packages/core/__tests__/detect-core-js.test.js | 35 | ||||
-rw-r--r-- | @linaria/packages/core/babel.config.js | 3 | ||||
-rw-r--r-- | @linaria/packages/core/package.json | 40 | ||||
-rw-r--r-- | @linaria/packages/core/src/CSSProperties.ts | 3 | ||||
-rw-r--r-- | @linaria/packages/core/src/StyledMeta.ts | 6 | ||||
-rw-r--r-- | @linaria/packages/core/src/css.ts | 15 | ||||
-rw-r--r-- | @linaria/packages/core/src/cx.ts | 9 | ||||
-rw-r--r-- | @linaria/packages/core/src/index.ts | 4 | ||||
-rw-r--r-- | @linaria/packages/core/tsconfig.json | 7 |
12 files changed, 191 insertions, 0 deletions
diff --git a/@linaria/packages/core/CHANGELOG.md b/@linaria/packages/core/CHANGELOG.md new file mode 100644 index 0000000..ba95b76 --- /dev/null +++ b/@linaria/packages/core/CHANGELOG.md @@ -0,0 +1,27 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +# [3.0.0-beta.4](https://github.com/callstack/linaria/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-05-07) + +**Note:** Version bump only for package @linaria/core + + + + + +# [3.0.0-beta.3](https://github.com/callstack/linaria/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-04-20) + +**Note:** Version bump only for package @linaria/core + + + + + +# [3.0.0-beta.2](https://github.com/callstack/linaria/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-04-11) + + +### Bug Fixes + +* **core:** remove unnecessary spread operators from css and cx ([#746](https://github.com/callstack/linaria/issues/746)) ([#749](https://github.com/callstack/linaria/issues/749)) ([de23a09](https://github.com/callstack/linaria/commit/de23a0926c2583db01e7df5ea9a134f5910f96a1)) diff --git a/@linaria/packages/core/README.md b/@linaria/packages/core/README.md new file mode 100644 index 0000000..0d75b37 --- /dev/null +++ b/@linaria/packages/core/README.md @@ -0,0 +1,35 @@ +<p align="center"> + <img alt="Linaria" src="https://raw.githubusercontent.com/callstack/linaria/HEAD/website/assets/linaria-logo@2x.png" width="496"> +</p> + +<p align="center"> +Zero-runtime CSS in JS library. +</p> + +--- + +### 📖 Please refer to the [GitHub](https://github.com/callstack/linaria#readme) for full documentation. + +## Features + +- Write CSS in JS, but with **zero runtime**, CSS is extracted to CSS files during build +- Familiar **CSS syntax** with Sass like nesting +- Use **dynamic prop based styles** with the React bindings, uses CSS variables behind the scenes +- Easily find where the style was defined with **CSS sourcemaps** +- **Lint your CSS** in JS with [stylelint](https://github.com/stylelint/stylelint) +- Use **JavaScript for logic**, no CSS preprocessor needed +- Optionally use any **CSS preprocessor** such as Sass or PostCSS + +**[Why use Linaria](../../docs/BENEFITS.md)** + +## Installation + +```sh +npm install @linaria/core @linaria/react @linaria/babel-preset @linaria/shaker +``` + +or + +```sh +yarn add @linaria/core @linaria/react @linaria/babel-preset @linaria/shaker +``` diff --git a/@linaria/packages/core/__tests__/cx.test.ts b/@linaria/packages/core/__tests__/cx.test.ts new file mode 100644 index 0000000..97fabff --- /dev/null +++ b/@linaria/packages/core/__tests__/cx.test.ts @@ -0,0 +1,7 @@ +import { cx } from '../src'; + +it('should filter falsy values', () => { + expect(cx('1', 'test', false, '2', 0, '', null, undefined, '3')).toBe( + '1 test 2 3' + ); +}); diff --git a/@linaria/packages/core/__tests__/detect-core-js.test.js b/@linaria/packages/core/__tests__/detect-core-js.test.js new file mode 100644 index 0000000..22bfbe4 --- /dev/null +++ b/@linaria/packages/core/__tests__/detect-core-js.test.js @@ -0,0 +1,35 @@ +import cp from 'child_process'; + +const waitForProcess = async (process) => { + return new Promise((resolve) => { + let output = ''; + process.stdout.on('data', (chunk) => { + output += chunk.toString(); + }); + process.on('close', () => { + resolve(output); + }); + }); +}; + +it('Ensures that package do not include core-js dependency after build', async () => { + // eslint-disable-next-line import/no-extraneous-dependencies + const packageJSON = require('@linaria/babel-preset/package.json'); + const buildScript = packageJSON.scripts['build:lib']; + + const proc = cp.exec(buildScript, { + stdio: 'ignore', + env: { + ...process.env, + DEBUG_CORE_JS: 'true', + }, + }); + const result = await waitForProcess(proc); + // run `DEBUG_CORE_JS=true yarn build:lib` to debug issues with introduced core-js dependency + expect(result).not.toContain( + 'The corejs3 polyfill added the following polyfills' + ); + expect(result).toContain( + 'Based on your code and targets, the corejs3 polyfill did not add any polyfill' + ); +}, 15000); diff --git a/@linaria/packages/core/babel.config.js b/@linaria/packages/core/babel.config.js new file mode 100644 index 0000000..c9ad680 --- /dev/null +++ b/@linaria/packages/core/babel.config.js @@ -0,0 +1,3 @@ +const config = require('../../babel.config'); + +module.exports = config; diff --git a/@linaria/packages/core/package.json b/@linaria/packages/core/package.json new file mode 100644 index 0000000..6026b2f --- /dev/null +++ b/@linaria/packages/core/package.json @@ -0,0 +1,40 @@ +{ + "name": "@linaria/core", + "version": "3.0.0-beta.4", + "publishConfig": { + "access": "public" + }, + "description": "Blazing fast zero-runtime CSS in JS library", + "sideEffects": false, + "main": "lib/index.js", + "module": "esm/index.js", + "types": "types/index.d.ts", + "files": [ + "types/", + "lib/", + "esm/" + ], + "license": "MIT", + "repository": "git@github.com:callstack/linaria.git", + "bugs": { + "url": "https://github.com/callstack/linaria/issues" + }, + "homepage": "https://github.com/callstack/linaria#readme", + "keywords": [ + "react", + "linaria", + "css", + "css-in-js", + "styled-components" + ], + "scripts": { + "build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start", + "build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start", + "build": "yarn build:lib && yarn build:esm", + "build:declarations": "tsc --emitDeclarationOnly --outDir types", + "prepare": "yarn build && yarn build:declarations", + "test": "jest --config ../../jest.config.js --rootDir .", + "typecheck": "tsc --noEmit --composite false", + "watch": "yarn build --watch" + } +} diff --git a/@linaria/packages/core/src/CSSProperties.ts b/@linaria/packages/core/src/CSSProperties.ts new file mode 100644 index 0000000..0c8e580 --- /dev/null +++ b/@linaria/packages/core/src/CSSProperties.ts @@ -0,0 +1,3 @@ +export type CSSProperties = { + [key: string]: string | number | CSSProperties; +}; diff --git a/@linaria/packages/core/src/StyledMeta.ts b/@linaria/packages/core/src/StyledMeta.ts new file mode 100644 index 0000000..e3aa691 --- /dev/null +++ b/@linaria/packages/core/src/StyledMeta.ts @@ -0,0 +1,6 @@ +export type StyledMeta = { + __linaria: { + className: string; + extends: StyledMeta; + }; +}; diff --git a/@linaria/packages/core/src/css.ts b/@linaria/packages/core/src/css.ts new file mode 100644 index 0000000..82c977f --- /dev/null +++ b/@linaria/packages/core/src/css.ts @@ -0,0 +1,15 @@ +import type { CSSProperties } from './CSSProperties'; +import type { StyledMeta } from './StyledMeta'; + +type CSS = ( + strings: TemplateStringsArray, + ...exprs: Array<string | number | CSSProperties | StyledMeta> +) => string; + +const css: CSS = () => { + throw new Error( + 'Using the "css" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly.' + ); +}; + +export default css; diff --git a/@linaria/packages/core/src/cx.ts b/@linaria/packages/core/src/cx.ts new file mode 100644 index 0000000..e34fae2 --- /dev/null +++ b/@linaria/packages/core/src/cx.ts @@ -0,0 +1,9 @@ +export type ClassName = string | false | void | null | 0; + +type CX = (...classNames: ClassName[]) => string; + +const cx: CX = function cx() { + return Array.prototype.slice.call(arguments).filter(Boolean).join(' '); +}; + +export default cx; diff --git a/@linaria/packages/core/src/index.ts b/@linaria/packages/core/src/index.ts new file mode 100644 index 0000000..60cdc6d --- /dev/null +++ b/@linaria/packages/core/src/index.ts @@ -0,0 +1,4 @@ +export { default as css } from './css'; +export { default as cx } from './cx'; +export type { CSSProperties } from './CSSProperties'; +export type { StyledMeta } from './StyledMeta'; diff --git a/@linaria/packages/core/tsconfig.json b/@linaria/packages/core/tsconfig.json new file mode 100644 index 0000000..3a01f90 --- /dev/null +++ b/@linaria/packages/core/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "paths": {}, + "rootDir": "src/" + } +} |