Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(babel): rename @linaria/babel to @linaria/babel-preset (#704) #720

Merged
merged 2 commits into from Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -37,13 +37,13 @@ Zero-runtime CSS in JS library.
## Installation

```sh
npm install @linaria/core @linaria/react @linaria/babel @linaria/shaker
npm install @linaria/core @linaria/react @linaria/babel-preset @linaria/shaker
```

or

```sh
yarn add @linaria/core @linaria/react @linaria/babel @linaria/shaker
yarn add @linaria/core @linaria/react @linaria/babel-preset @linaria/shaker
```

## Setup
Expand All @@ -59,14 +59,14 @@ Or configure Linaria with one of the following integrations:
- [Preact](/docs/CONFIGURATION.md#preact)
- [Gatsby](/docs/CONFIGURATION.md#gatsby)

Optionally, add the `linaria/babel` preset to your Babel configuration at the end of the presets list to avoid errors when importing the components in your server code or tests:
Optionally, add the `@linaria` preset to your Babel configuration at the end of the presets list to avoid errors when importing the components in your server code or tests:

```json
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"module:@linaria/babel"
"@linaria"
]
}
```
Expand Down
14 changes: 7 additions & 7 deletions docs/CONFIGURATION.md
Expand Up @@ -81,11 +81,11 @@ module.exports = {

If you need to specify custom babel configuration, you can pass them here. These babel options will be used by Linaria when parsing and evaluating modules.

## `@linaria/babel` preset
## `@linaria/babel-preset`

The preset pre-processes and evaluates the CSS. The bundler plugins use this preset under the hood. You also might want to use this preset if you import the components outside of the files handled by your bundler, such as on your server or in unit tests.

To use this preset, add `@linaria/babel` to your Babel configuration at the end of the presets list:
To use this preset, add `@linaria/babel-preset` to your Babel configuration at the end of the presets list:

`.babelrc`:

Expand All @@ -94,7 +94,7 @@ To use this preset, add `@linaria/babel` to your Babel configuration at the end
"presets": [
"@babel/preset-env",
"@babel/preset-react",
+ "@linaria/babel"
+ "@linaria"
]
}
```
Expand Down Expand Up @@ -129,7 +129,7 @@ After that, your `package.json` should look like the following:
"sirv-cli": "^0.4.5"
},
"dependencies": {
+ "@linaria/babel": "^3.0.0",
+ "@linaria/babel-preset": "^3.0.0",
+ "@linaria/core": "^3.0.0",
+ "@linaria/react": "^3.0.0",
+ "@linaria/webpack-loader": "^3.0.0",
Expand All @@ -146,7 +146,7 @@ Now in your `preact.config.js`, we will modify the babel rule to use the necessa
```js
export default config => {
const { options, ...babelLoaderRule } = config.module.rules[0]; // Get the babel rule and options
options.presets.push('@babel/preset-react', '@linaria/babel'); // Push the necessary presets
options.presets.push('@babel/preset-react', '@linaria'); // Push the necessary presets
config.module.rules[0] = {
...babelLoaderRule,
loader: undefined, // Disable the predefined babel-loader on the rule
Expand Down Expand Up @@ -231,14 +231,14 @@ You can also take a look at the example [here](../examples/gatsby/plugin)

This is a bit more advanced way of integrating Linaria into your Gatsby project.

First, you will need to install `@linaria/babel` and `babel-preset-gatsby`. Then, create `babel.config.js` in the root of your project with the following contents:
First, you will need to install `@linaria/babel-preset` and `babel-preset-gatsby`. Then, create `babel.config.js` in the root of your project with the following contents:

```js
module.exports = {
presets: [
'babel-preset-gatsby',
[
'@linaria/babel',
'@linaria',
{
evaluate: true,
displayName: process.env.NODE_ENV !== 'production',
Expand Down
8 changes: 4 additions & 4 deletions packages/babel/__utils__/strategy-tester.ts
Expand Up @@ -248,7 +248,7 @@ export function run(
const { code, metadata } = await transpile(
dedent`
import { styled } from '@linaria/react';
import slugify from '@linaria/babel/__fixtures__/slugify';
import slugify from '@linaria/babel-preset/__fixtures__/slugify';

export const Title = styled.h1\`
&:before {
Expand All @@ -266,7 +266,7 @@ export function run(
const { code, metadata } = await transpile(
dedent`
import { styled } from '@linaria/react';
const slugify = require('@linaria/babel/__fixtures__/slugify').default;
const slugify = require('@linaria/babel-preset/__fixtures__/slugify').default;

const boo = t => slugify(t) + 'boo';
const bar = t => slugify(t) + 'bar';
Expand All @@ -287,7 +287,7 @@ export function run(
const { code, metadata } = await transpile(
dedent`
import { styled } from '@linaria/react';
const slugify = require('@linaria/babel/__fixtures__/slugify').default;
const slugify = require('@linaria/babel-preset/__fixtures__/slugify').default;

const boo = t => slugify(t) + 'boo';
const bar = t => slugify(t) + 'bar';
Expand Down Expand Up @@ -858,7 +858,7 @@ export function run(
dedent`
import React from 'react'
import {css} from '@linaria/core'
import externalDep from '@linaria/babel/__fixtures__/sample-script';
import externalDep from '@linaria/babel-preset/__fixtures__/sample-script';
const globalObj = {
opacity: 0.5,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/babel/package.json
@@ -1,5 +1,5 @@
{
"name": "@linaria/babel",
"name": "@linaria/babel-preset",
"version": "3.0.0-beta.0",
"publishConfig": {
"access": "public"
Expand Down
3 changes: 2 additions & 1 deletion packages/babel/src/evaluators/buildOptions.ts
Expand Up @@ -65,7 +65,8 @@ export default function buildOptions(
// This case won't get caught and the preset won't filtered, even if they are same
// So we add an extra check for top level linaria/babel
name === 'linaria/babel' ||
name === '@linaria/babel' ||
name === '@linaria' ||
name === '@linaria/babel-preset' ||
name === require.resolve('../index') ||
// Also add a check for the plugin names we include for bundler support
plugins.includes(name)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Expand Up @@ -43,7 +43,7 @@
"@types/normalize-path": "^3.0.0"
},
"dependencies": {
"@linaria/babel": "^3.0.0-beta.0",
"@linaria/babel-preset": "^3.0.0-beta.0",
"glob": "^7.1.3",
"mkdirp": "^0.5.1",
"normalize-path": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Expand Up @@ -8,7 +8,7 @@ import normalize from 'normalize-path';
import mkdirp from 'mkdirp';
import glob from 'glob';
import yargs from 'yargs';
import { transform } from '@linaria/babel';
import { transform } from '@linaria/babel-preset';

const { argv } = yargs
.usage('Usage: $0 [options] <files ...>')
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/tsconfig.json
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {},
"rootDir": "src/"
},
"compilerOptions": { "paths": {}, "rootDir": "src/" },
"references": [{ "path": "../babel" }]
}
2 changes: 1 addition & 1 deletion packages/core/__tests__/detect-core-js.test.js
Expand Up @@ -14,7 +14,7 @@ const waitForProcess = async (process) => {

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/package.json');
const packageJSON = require('@linaria/babel-preset/package.json');
const buildScript = packageJSON.scripts['build:lib'];

const proc = cp.exec(buildScript, {
Expand Down
Expand Up @@ -228,7 +228,7 @@ Dependencies: NA

exports[`extractor evaluates expressions with dependencies 1`] = `
"import { styled } from '@linaria/react';
import slugify from '@linaria/babel/__fixtures__/slugify';
import slugify from '@linaria/babel-preset/__fixtures__/slugify';
export const Title = /*#__PURE__*/styled(\\"h1\\")({
name: \\"Title\\",
class: \\"Title_t1t92lw9\\"
Expand All @@ -245,14 +245,14 @@ CSS:
}
}

Dependencies: @babel/runtime/helpers/interopRequireDefault, @linaria/babel/__fixtures__/slugify
Dependencies: @babel/runtime/helpers/interopRequireDefault, @linaria/babel-preset/__fixtures__/slugify

`;

exports[`extractor evaluates expressions with expressions depending on shared dependency 1`] = `
"import { styled } from '@linaria/react';

const slugify = require('@linaria/babel/__fixtures__/slugify').default;
const slugify = require('@linaria/babel-preset/__fixtures__/slugify').default;

const boo = t => slugify(t) + 'boo';

Expand All @@ -274,7 +274,7 @@ CSS:
}
}

Dependencies: @linaria/babel/__fixtures__/slugify
Dependencies: @linaria/babel-preset/__fixtures__/slugify

`;

Expand Down Expand Up @@ -388,7 +388,7 @@ Dependencies: NA
exports[`extractor evaluates multiple expressions with shared dependency 1`] = `
"import { styled } from '@linaria/react';

const slugify = require('@linaria/babel/__fixtures__/slugify').default;
const slugify = require('@linaria/babel-preset/__fixtures__/slugify').default;

const boo = t => slugify(t) + 'boo';

Expand All @@ -411,7 +411,7 @@ CSS:
}
}

Dependencies: @linaria/babel/__fixtures__/slugify
Dependencies: @linaria/babel-preset/__fixtures__/slugify

`;

Expand Down Expand Up @@ -876,7 +876,7 @@ Dependencies: NA
exports[`extractor should process \`css\` calls with complex interpolation inside components 1`] = `
"import React from 'react';
import { css } from '@linaria/core';
import externalDep from '@linaria/babel/__fixtures__/sample-script';
import externalDep from '@linaria/babel-preset/__fixtures__/sample-script';
const globalObj = {
opacity: 0.5
};
Expand Down Expand Up @@ -914,7 +914,7 @@ CSS:
}
}

Dependencies: @babel/runtime/helpers/interopRequireDefault, @linaria/babel/__fixtures__/sample-script
Dependencies: @babel/runtime/helpers/interopRequireDefault, @linaria/babel-preset/__fixtures__/sample-script

`;

Expand Down
2 changes: 1 addition & 1 deletion packages/extractor/__tests__/extractor.test.ts
@@ -1,4 +1,4 @@
import { run } from '@linaria/babel/__utils__/strategy-tester';
import { run } from '@linaria/babel-preset/__utils__/strategy-tester';

describe('extractor', () => {
run(__dirname, require('../src').default);
Expand Down
2 changes: 1 addition & 1 deletion packages/extractor/package.json
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@babel/generator": ">=7",
"@babel/plugin-transform-runtime": ">=7",
"@linaria/babel": "^3.0.0-beta.0",
"@linaria/babel-preset": "^3.0.0-beta.0",
"@linaria/preeval": "^3.0.0-beta.0"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/extractor/src/index.ts
Expand Up @@ -15,8 +15,8 @@ import { parseSync, transformSync } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import generator from '@babel/generator';

import type { Evaluator } from '@linaria/babel';
import { buildOptions } from '@linaria/babel';
import type { Evaluator } from '@linaria/babel-preset';
import { buildOptions } from '@linaria/babel-preset';
import RequirementsResolver from './RequirementsResolver';

function isMemberExpression(
Expand Down
5 changes: 1 addition & 4 deletions packages/extractor/tsconfig.json
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {},
"rootDir": "src/"
},
"compilerOptions": { "paths": {}, "rootDir": "src/" },
"references": [{ "path": "../babel" }, { "path": "../preeval" }]
}
2 changes: 1 addition & 1 deletion packages/linaria/package.json
Expand Up @@ -42,7 +42,7 @@
"watch": "yarn build --watch"
},
"dependencies": {
"@linaria/babel": "^3.0.0-beta.0",
"@linaria/babel-preset": "^3.0.0-beta.0",
"@linaria/core": "^3.0.0-beta.0",
"@linaria/extractor": "^3.0.0-beta.0",
"@linaria/react": "^3.0.0-beta.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/linaria/src/babel.ts
@@ -1,4 +1,4 @@
import babel from '@linaria/babel';
import babel from '@linaria/babel-preset';

export default babel;
export * from '@linaria/babel';
export * from '@linaria/babel-preset';
2 changes: 1 addition & 1 deletion packages/preeval/package.json
Expand Up @@ -38,7 +38,7 @@
"watch": "yarn build --watch"
},
"dependencies": {
"@linaria/babel": "^3.0.0-beta.0"
"@linaria/babel-preset": "^3.0.0-beta.0"
},
"peerDependencies": {
"@babel/core": ">=7"
Expand Down
4 changes: 2 additions & 2 deletions packages/preeval/src/index.ts
Expand Up @@ -4,14 +4,14 @@
*/
import type { NodePath } from '@babel/traverse';
import type { Program } from '@babel/types';
import type { State, StrictOptions } from '@linaria/babel';
import type { State, StrictOptions } from '@linaria/babel-preset';
import {
GenerateClassNames,
DetectStyledImportName,
JSXElement,
ProcessStyled,
ProcessCSS,
} from '@linaria/babel';
} from '@linaria/babel-preset';
import { Core } from './babel';

function index(babel: Core, options: StrictOptions) {
Expand Down
5 changes: 1 addition & 4 deletions packages/preeval/tsconfig.json
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {},
"rootDir": "src/"
},
"compilerOptions": { "paths": {}, "rootDir": "src/" },
"references": [{ "path": "../babel" }]
}
2 changes: 1 addition & 1 deletion packages/react/__tests__/detect-core-js.test.js
Expand Up @@ -14,7 +14,7 @@ const waitForProcess = async (process) => {

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/package.json');
const packageJSON = require('@linaria/babel-preset/package.json');
const buildScript = packageJSON.scripts['build:lib'];

const proc = cp.exec(buildScript, {
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup/package.json
Expand Up @@ -43,7 +43,7 @@
"rollup": "1.20.0||^2.0.0"
},
"dependencies": {
"@linaria/babel": "^3.0.0-beta.0",
"@linaria/babel-preset": "^3.0.0-beta.0",
"@rollup/pluginutils": "^4.1.0"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/rollup/src/index.ts
Expand Up @@ -5,8 +5,8 @@
*/

import { createFilter } from '@rollup/pluginutils';
import { transform, slugify } from '@linaria/babel';
import type { PluginOptions, Preprocessor } from '@linaria/babel';
import { transform, slugify } from '@linaria/babel-preset';
import type { PluginOptions, Preprocessor } from '@linaria/babel-preset';

type RollupPluginOptions = {
include?: string | string[];
Expand Down
5 changes: 1 addition & 4 deletions packages/rollup/tsconfig.json
@@ -1,8 +1,5 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {},
"rootDir": "src/"
},
"compilerOptions": { "paths": {}, "rootDir": "src/" },
"references": [{ "path": "../babel" }]
}