diff options
author | Sebastian <sebasjm@gmail.com> | 2021-08-23 16:46:06 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-08-23 16:48:30 -0300 |
commit | 38acabfa6089ab8ac469c12b5f55022fb96935e5 (patch) | |
tree | 453dbf70000cc5e338b06201af1eaca8343f8f73 /@linaria/packages/preeval | |
parent | f26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff) | |
download | node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2 node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip |
Diffstat (limited to '@linaria/packages/preeval')
-rw-r--r-- | @linaria/packages/preeval/CHANGELOG.md | 51 | ||||
-rw-r--r-- | @linaria/packages/preeval/README.md | 35 | ||||
-rw-r--r-- | @linaria/packages/preeval/babel.config.js | 3 | ||||
-rw-r--r-- | @linaria/packages/preeval/package.json | 46 | ||||
-rw-r--r-- | @linaria/packages/preeval/src/babel.ts | 3 | ||||
-rw-r--r-- | @linaria/packages/preeval/src/index.ts | 88 | ||||
-rw-r--r-- | @linaria/packages/preeval/tsconfig.json | 5 |
7 files changed, 231 insertions, 0 deletions
diff --git a/@linaria/packages/preeval/CHANGELOG.md b/@linaria/packages/preeval/CHANGELOG.md new file mode 100644 index 0000000..831fdd1 --- /dev/null +++ b/@linaria/packages/preeval/CHANGELOG.md @@ -0,0 +1,51 @@ +# 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.8](https://github.com/callstack/linaria/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-07-18) + + +### Bug Fixes + +* **shaker:** named exports are removed (fixes [#800](https://github.com/callstack/linaria/issues/800)) ([#801](https://github.com/callstack/linaria/issues/801)) ([3421930](https://github.com/callstack/linaria/commit/3421930b26608b41a02f8b776562655d755a23b4)) + + + + + +# [3.0.0-beta.7](https://github.com/callstack/linaria/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-06-24) + +**Note:** Version bump only for package @linaria/preeval + + + + + +# [3.0.0-beta.5](https://github.com/callstack/linaria/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-05-31) + +**Note:** Version bump only for package @linaria/preeval + + + + + +# [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/preeval + + + + + +# [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/preeval + + + + + +# [3.0.0-beta.2](https://github.com/callstack/linaria/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-04-11) + +**Note:** Version bump only for package @linaria/preeval diff --git a/@linaria/packages/preeval/README.md b/@linaria/packages/preeval/README.md new file mode 100644 index 0000000..0d75b37 --- /dev/null +++ b/@linaria/packages/preeval/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/preeval/babel.config.js b/@linaria/packages/preeval/babel.config.js new file mode 100644 index 0000000..c9ad680 --- /dev/null +++ b/@linaria/packages/preeval/babel.config.js @@ -0,0 +1,3 @@ +const config = require('../../babel.config'); + +module.exports = config; diff --git a/@linaria/packages/preeval/package.json b/@linaria/packages/preeval/package.json new file mode 100644 index 0000000..5950ec0 --- /dev/null +++ b/@linaria/packages/preeval/package.json @@ -0,0 +1,46 @@ +{ + "name": "@linaria/preeval", + "version": "3.0.0-beta.8", + "publishConfig": { + "access": "public" + }, + "description": "Blazing fast zero-runtime CSS in JS library", + "main": "lib/index.js", + "module": "esm/index.js", + "types": "types", + "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", + "babel-plugin", + "babel" + ], + "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", + "typecheck": "tsc --noEmit --composite false", + "watch": "yarn build --watch" + }, + "dependencies": { + "@linaria/babel-preset": "^3.0.0-beta.7" + }, + "peerDependencies": { + "@babel/core": ">=7" + } +} diff --git a/@linaria/packages/preeval/src/babel.ts b/@linaria/packages/preeval/src/babel.ts new file mode 100644 index 0000000..d99a54b --- /dev/null +++ b/@linaria/packages/preeval/src/babel.ts @@ -0,0 +1,3 @@ +import type core from '@babel/core'; + +export type Core = typeof core; diff --git a/@linaria/packages/preeval/src/index.ts b/@linaria/packages/preeval/src/index.ts new file mode 100644 index 0000000..6197ce0 --- /dev/null +++ b/@linaria/packages/preeval/src/index.ts @@ -0,0 +1,88 @@ +/** + * This file is a babel preset used to transform files inside evaluators. + * It works the same as main `babel/extract` preset, but do not evaluate lazy dependencies. + */ +import type { NodePath } from '@babel/traverse'; +import type { Program, Statement, VariableDeclaration } from '@babel/types'; +import type { State, StrictOptions } from '@linaria/babel-preset'; +import { + GenerateClassNames, + DetectStyledImportName, + JSXElement, + ProcessStyled, + ProcessCSS, +} from '@linaria/babel-preset'; +import { Core } from './babel'; + +const isHoistableExport = ( + node: NodePath<Statement> +): node is NodePath<Statement> & NodePath<VariableDeclaration> => { + // Only `var` can be hoisted + if (!node.isVariableDeclaration({ kind: 'var' })) return false; + + const declarations = node.get('declarations'); + + // Our target has only one declaration + if (!Array.isArray(declarations) || declarations.length !== 1) return false; + + const init = declarations[0].get('init'); + // It should be initialized with CallExpression… + if (!init || Array.isArray(init) || !init.isCallExpression()) return false; + + const callee = init.get('callee'); + // … which callee should be `required` … + if (Array.isArray(callee) || !callee.isIdentifier({ name: 'require' })) + return false; + + // … which should be a global identifier + return !callee.scope.hasReference('require'); +}; + +function index(babel: Core, options: StrictOptions) { + return { + visitor: { + Program: { + enter(path: NodePath<Program>, state: State) { + // Collect all the style rules from the styles we encounter + state.queue = []; + state.rules = {}; + state.index = -1; + state.dependencies = []; + state.replacements = []; + + // We need our transforms to run before anything else + // So we traverse here instead of a in a visitor + path.traverse({ + ImportDeclaration: (p) => DetectStyledImportName(babel, p, state), + TaggedTemplateExpression: (p) => + GenerateClassNames(babel, p, state, options), + JSXElement, + }); + }, + exit(path: NodePath<Program>) { + /* A really dirty hack that solves https://github.com/callstack/linaria/issues/800 + * Sometimes babel inserts `require` after usages of required modules. + * It makes the shaker sad. As a temporary solution, we hoist requires. + * This hack should be deleted after transition `shaker` to @babel/traverse + */ + path + .get('body') + .filter(isHoistableExport) + .forEach((p) => { + const node = p.node; + p.remove(); + path.unshiftContainer('body', node); + }); + }, + }, + CallExpression: ProcessStyled, + TaggedTemplateExpression: ProcessCSS, // TaggedTemplateExpression is processed before CallExpression + }, + }; +} + +export default function preset(context: any, options: StrictOptions) { + return { + plugins: [[index, options]], + }; +} diff --git a/@linaria/packages/preeval/tsconfig.json b/@linaria/packages/preeval/tsconfig.json new file mode 100644 index 0000000..38139ee --- /dev/null +++ b/@linaria/packages/preeval/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { "paths": {}, "rootDir": "src/" }, + "references": [{ "path": "../babel" }] +} |