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

Use the new compiler in Vite plugin #1264

Merged
merged 63 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
cf6c5c8
bump Babel presets, Vitest, Preconstruct, enable dynamic import
mrm007 Dec 26, 2023
8318ad2
update lockfile
mrm007 Dec 26, 2023
6a88b91
ignore warnings in esbuild fixture runner
mrm007 Dec 26, 2023
a0ca76d
add `thirdparty` fixture
mrm007 Dec 26, 2023
a5f95e6
update lockfile
mrm007 Dec 26, 2023
211e07d
dedupe lockfile
mrm007 Dec 26, 2023
973e526
run tests with `thirdparty` fixture
mrm007 Dec 26, 2023
4948682
default to emitCssInSsr: true
mrm007 Dec 19, 2023
3351e36
bump Vite to latest
mrm007 Dec 19, 2023
05f4f5c
integrate new compiler into Vite plugin
mrm007 Dec 20, 2023
30a2b65
run tests against Vite plugin with new compiler
mrm007 Dec 20, 2023
81eb2cb
add a changeset
mrm007 Dec 20, 2023
6d29ca1
refactor `addFileScope` to be able to add the global adapter on alrea…
mrm007 Dec 20, 2023
bfbd7eb
createCompiler: use absolute ids everywhere
mrm007 Dec 20, 2023
1760a42
resolve relative and SSR module ids to absolute ids
mrm007 Dec 23, 2023
ce75827
close the compiler on build end
mrm007 Dec 23, 2023
1aa6248
strip out PostCSS logic because Vite handles it now
mrm007 Dec 23, 2023
b26a4bc
createCompiler: go back to relative ids
mrm007 Dec 26, 2023
27fa1a8
update lockfile
mrm007 Dec 26, 2023
7923c54
compute relative path using the platform-specific function
mrm007 Dec 27, 2023
55a1805
add missing function calls
mrm007 Dec 27, 2023
8314085
install `@types/node` at the monorepo root
mrm007 Dec 27, 2023
5b505c0
add a platform-specific test for `addFileScope`
mrm007 Dec 27, 2023
60e5bd7
simplify
mrm007 Dec 27, 2023
faef737
configure Vitest extension in VS Code
mrm007 Dec 27, 2023
3afdb0a
back to preset-env
mrm007 Dec 27, 2023
adeef87
lazy load Vite to avoid the CJS warning
mrm007 Dec 27, 2023
72a204a
changesets
mrm007 Dec 27, 2023
2220d95
hide console output behind a `DEBUG` flag
mrm007 Dec 28, 2023
0c4d618
make `vite` an optional peer dependency
mrm007 Dec 28, 2023
236c3c6
tests for `normalizePath`
mrm007 Dec 28, 2023
c2594da
changesets
mrm007 Dec 28, 2023
51e0e93
Merge branch 'babel-modern' into thirdparty-fixture
mrm007 Dec 28, 2023
e663a6d
Merge branch 'thirdparty-fixture' into vite-plugin-new
mrm007 Dec 28, 2023
869febf
improve file watching logic
mrm007 Dec 29, 2023
132be17
better logging
mrm007 Dec 29, 2023
eaae98e
better path resolution for monorepos
mrm007 Dec 29, 2023
6de4f7a
make compiler the default and introduce a `mode: esbuild` option to u…
mrm007 Dec 29, 2023
0d29be7
when in SSR mode, emit CSS the same way for both compilation methods
mrm007 Dec 29, 2023
7e26050
rename `mode` to `compiler`, add `mode: transform` and `mode: emitCss`
mrm007 Jan 2, 2024
73592b0
update changesets
mrm007 Jan 2, 2024
3133d4c
abolish `emitCssInSsr` and update changesets
mrm007 Jan 6, 2024
e69a208
Merge branch 'master' into babel-modern
mrm007 Jan 8, 2024
5daa69d
move `resolveId` and `load` hooks after `transform`
mrm007 Jan 10, 2024
fb3c62c
tweak root Babel config
mrm007 Jan 15, 2024
fd61f2f
update changeset
mrm007 Jan 15, 2024
0e13253
remove `esbuildOptions`, add `unstable_mode`
mrm007 Jan 15, 2024
120be2f
remove `vite-next` fixture type
mrm007 Jan 15, 2024
66fc42c
remove `vite-next` fixture type
mrm007 Jan 15, 2024
dc6aa4b
update docs
mrm007 Jan 15, 2024
45e5cfd
Merge branch 'babel-modern' into vite-plugin-new
mrm007 Jan 15, 2024
551f822
correctly watch files in `build` mode
mrm007 Jan 16, 2024
e157792
Merge remote-tracking branch 'origin/master' into vite-plugin-new
mrm007 Jan 16, 2024
a5a43e9
Vite is not an optional peer dependency
mrm007 Jan 16, 2024
402f5b1
remove redundant changeset
mrm007 Jan 16, 2024
692349d
add a changeste for `esbuildOptions`
mrm007 Jan 16, 2024
0777194
update changesets
mrm007 Jan 16, 2024
30f23a9
reorganise test-helpers deps
mrm007 Jan 16, 2024
af34dca
Merge branch 'master' into vite-plugin-new
mrm007 Jan 18, 2024
990681e
feedback from code review
mrm007 Jan 23, 2024
fb61d07
drop support for Vite < 4
mrm007 Jan 23, 2024
79119b2
Merge remote-tracking branch 'origin/master' into vite-plugin-new
mrm007 Jan 25, 2024
030d8df
Merge branch 'master' into vite-plugin-new
mrm007 Jan 27, 2024
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
5 changes: 5 additions & 0 deletions .changeset/integration-deps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/integration': patch
---

Update dependencies
14 changes: 14 additions & 0 deletions .changeset/integration-normalizePath.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@vanilla-extract/integration': minor
---

Export a `normalizePath` function that converts path separators to forward slashes

**Example usage**

```ts
import { normalizePath } from '@vanilla-extract/integration';

normalizePath('foo\\bar'); // 'foo/bar'
normalizePath('foo/bar'); // 'foo/bar'
```
9 changes: 9 additions & 0 deletions .changeset/vite-plugin-compiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@vanilla-extract/vite-plugin': major
---

The Vite plugin now uses a newer, faster, Vite-based compiler by default.

The new compiler uses [`vite-node`](https://github.com/vitest-dev/vitest/tree/main/packages/vite-node) to parse and extract CSS from `.css.ts` files. This comes with all the benefits of using Vite, faster builds and the ability to use Vite plugins.

The new compiler has been used in Remix ever since support for Vanilla Extract was introduced.
7 changes: 7 additions & 0 deletions .changeset/vite-plugin-emitCssInSsr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@vanilla-extract/vite-plugin': major
---

The behaviour previously known as `emitCssInSsr` has been turned on by default. The `emitCssInSsr` option has been removed.

This means that the CSS emitted by the plugin is now processed by Vite, so the plugin no longer needs to resolve PostCSS plugins and process the CSS output itself.
5 changes: 5 additions & 0 deletions .changeset/vite-plugin-esbuildOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/vite-plugin': major
---

The `esbuildOptions` option has been removed as we are no longer using esbuild internally
5 changes: 5 additions & 0 deletions .changeset/vite-plugin-supported.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/vite-plugin': major
---

Drop support for Vite < 4
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@swc/core": "^1.2.112",
"@testing-library/jest-dom": "^5.11.9",
"@types/jest": "^29.2.5",
"@types/node": "^20.9.5",
"@types/testing-library__jest-dom": "^5.14.5",
"@vanilla-extract/jest-transform": "*",
"babel-jest": "^27.3.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"find-up": "^5.0.0",
"javascript-stringify": "^2.0.1",
"lodash": "^4.17.21",
"mlly": "^1.1.0",
"mlly": "^1.4.2",
"outdent": "^0.8.0",
"vite": "^5.0.10",
"vite-node": "^1.1.0"
"vite": "^5.0.11",
"vite-node": "^1.2.0"
},
"devDependencies": {
"@types/babel__core": "^7.1.20",
Expand Down
141 changes: 88 additions & 53 deletions packages/integration/src/addFileScope.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { outdent } from 'outdent';
import { addFileScope } from './addFileScope';
import { sep, posix, win32 } from 'path';

import { addFileScope, normalizePath } from './addFileScope';

const raw = String.raw;

// remove quotes around the snapshot
expect.addSnapshotSerializer({
test: (val) => typeof val === 'string',
print: (val) => (val as string).trim(),
});

describe('ESM', () => {
test('should add missing fileScope', () => {
Expand All @@ -17,16 +27,12 @@ describe('ESM', () => {
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
"

import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("app/app.css.ts", "my-package");
import {style} from '@vanilla-extract/css';
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("app/app.css.ts", "my-package");
import {style} from '@vanilla-extract/css';

export const myStyle = style({});
endFileScope();

"
endFileScope();
`);
});

Expand All @@ -46,19 +52,15 @@ describe('ESM', () => {
globalAdapterIdentifier: 'MY_GLOBAL_ADAPTER',
}),
).toMatchInlineSnapshot(`
"

import * as __vanilla_css_adapter__ from "@vanilla-extract/css/adapter";
__vanilla_css_adapter__.setAdapter(MY_GLOBAL_ADAPTER);

import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("app/app.css.ts", "my-package");
import {style} from '@vanilla-extract/css';
import * as __vanilla_css_adapter__ from "@vanilla-extract/css/adapter";
__vanilla_css_adapter__.setAdapter(MY_GLOBAL_ADAPTER);
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("app/app.css.ts", "my-package");
import {style} from '@vanilla-extract/css';

export const myStyle = style({});
endFileScope();
__vanilla_css_adapter__.removeAdapter();
"
endFileScope();
__vanilla_css_adapter__.removeAdapter();
`);
});

Expand All @@ -80,12 +82,12 @@ describe('ESM', () => {
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
"import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("app/app.css.ts", "my-package");
import {style} from '@vanilla-extract/css';

export const myStyle = style({});
endFileScope();"
endFileScope();
`);
});

Expand All @@ -110,12 +112,12 @@ describe('ESM', () => {
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
"import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("app/app.css.ts", "my-package");
import {style} from '@vanilla-extract/css';

export const myStyle = style({});
endFileScope();"
endFileScope();
`);
});

Expand All @@ -137,13 +139,13 @@ describe('ESM', () => {
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
"import * as vanillaFileScope from "@vanilla-extract/css/fileScope";
vanillaFileScope.setFileScope("app/app.css.ts", "my-package");
import {style} from '@vanilla-extract/css';
import * as vanillaFileScope from "@vanilla-extract/css/fileScope";
vanillaFileScope.setFileScope("app/app.css.ts", "my-package");
import {style} from '@vanilla-extract/css';

export const myStyle = style({});
vanillaFileScope.endFileScope();"
`);
export const myStyle = style({});
vanillaFileScope.endFileScope();
`);
});
});

Expand All @@ -164,17 +166,13 @@ describe('CJS', () => {
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
"

const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
__vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
const _css = require('@vanilla-extract/css');
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
__vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
const _css = require('@vanilla-extract/css');

var myStyle = _css.style({});
exports.myStyle = myStyle;
__vanilla_filescope__.endFileScope();
;
"
__vanilla_filescope__.endFileScope();
`);
});

Expand All @@ -195,20 +193,16 @@ describe('CJS', () => {
globalAdapterIdentifier: 'MY_GLOBAL_ADAPTER',
}),
).toMatchInlineSnapshot(`
"

const __vanilla_css_adapter__ = require("@vanilla-extract/css/adapter");
__vanilla_css_adapter__.setAdapter(MY_GLOBAL_ADAPTER);

const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
__vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
const _css = require('@vanilla-extract/css');
const __vanilla_css_adapter__ = require("@vanilla-extract/css/adapter");
__vanilla_css_adapter__.setAdapter(MY_GLOBAL_ADAPTER);
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
__vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
const _css = require('@vanilla-extract/css');

var myStyle = _css.style({});
exports.myStyle = myStyle;
__vanilla_filescope__.endFileScope();
__vanilla_css_adapter__.removeAdapter();;
"
__vanilla_filescope__.endFileScope();
__vanilla_css_adapter__.removeAdapter();
`);
});

Expand All @@ -231,13 +225,13 @@ describe('CJS', () => {
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
"const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
__vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
const _css = require('@vanilla-extract/css');

var myStyle = _css.style({});
exports.myStyle = myStyle;
__vanilla_filescope__.endFileScope();"
__vanilla_filescope__.endFileScope();
`);
});

Expand All @@ -263,13 +257,54 @@ describe('CJS', () => {
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
"const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
__vanilla_filescope__.setFileScope("app/app.css.ts", "my-package");
const _css = require('@vanilla-extract/css');

const myStyle = _css.style({});
exports.myStyle = myStyle;
__vanilla_filescope__.endFileScope();"
__vanilla_filescope__.endFileScope();
`);
});
});

test('platform-specific relative path', () => {
const { rootPath, filePath } = {
[posix.sep]: {
rootPath: '/the-root',
filePath: '/the-root/app/app.css.ts',
},
[win32.sep]: {
rootPath: raw`D:\the-root`,
filePath: raw`D:\the-root\app\app.css.ts`,
},
}[sep];

const source = outdent`
import { style } from '@vanilla-extract/css';

export const myStyle = style({});
`;

// The snapshot should be the same for either platform
expect(
addFileScope({
source,
rootPath,
filePath,
packageName: 'my-package',
}),
).toMatchInlineSnapshot(`
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
setFileScope("app/app.css.ts", "my-package");
import { style } from '@vanilla-extract/css';

export const myStyle = style({});
endFileScope();
`);
});

test('normalizePath()', () => {
expect(normalizePath(raw`foo\bar`)).toMatchInlineSnapshot(`foo/bar`);
expect(normalizePath(raw`foo/bar`)).toMatchInlineSnapshot(`foo/bar`);
});