Skip to content

Commit d83abf2

Browse files
committed
fix!: Remove deprecated jiti entrypoint loader (#1087)
1 parent 239dada commit d83abf2

File tree

12 files changed

+39
-333
lines changed

12 files changed

+39
-333
lines changed

docs/guide/essentials/config/entrypoint-loaders.md

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,3 @@ If you're running into errors while importing entrypoints, run `wxt prepare --de
1717
:::
1818

1919
Once the environment has been polyfilled and your code pre-processed, it's up the entrypoint loader to import your code, extracting the options from the default export.
20-
21-
There are two options for loading your entrypoints:
22-
23-
1. `vite-node` - default as of `v0.19.0`
24-
2. `jiti` (**DEPRECATED, will be removed in `v0.20.0`**) - Default before `v0.19.0`
25-
26-
## vite-node
27-
28-
Since 0.19.0, WXT uses `vite-node`, the same tool that powers Vitest and Nuxt, to import your entrypoint files. It re-uses the same vite config used when building your extension, making it the most stable entrypoint loader.
29-
30-
## jiti
31-
32-
To enable `jiti`:
33-
34-
```ts
35-
export default defineConfig({
36-
entrypointLoader: 'jiti',
37-
});
38-
```
39-
40-
This is the original method WXT used to import TS files. However, because it doesn't support vite plugins like `vite-node`, it does one additional pre-processing step: It removes **_ALL_** imports from your code.
41-
42-
That means you cannot use imported variables outside the `main` function in JS entrypoints, like for content script `matches` or other options:
43-
44-
```ts
45-
// entrypoints/content.ts
46-
import { GOOGLE_MATCHES } from '~/utils/match-patterns';
47-
48-
export default defineContentScript({
49-
matches: GOOGLE_MATCHES,
50-
main() {
51-
// ...
52-
},
53-
});
54-
```
55-
56-
```
57-
$ wxt build
58-
wxt build
59-
60-
WXT 0.14.1
61-
ℹ Building chrome-mv3 for production with Vite 5.0.5
62-
✖ Command failed after 360 ms
63-
64-
[8:55:54 AM] ERROR entrypoints/content.ts: Cannot use imported variable "GOOGLE_MATCHES" before main function.
65-
```
66-
67-
Usually, this error occurs when you try to extract options into a shared file or when running code outside the `main` function. To fix the example from above, use literal values when defining an entrypoint instead of importing them:
68-
69-
```ts
70-
import { GOOGLE_MATCHES } from '~/utils/match-patterns'; // [!code --]
71-
72-
export default defineContentScript({
73-
matches: GOOGLE_MATCHES, // [!code --]
74-
matches: ['*//*.google.com/*'], // [!code ++]
75-
main() {
76-
// ...
77-
},
78-
});
79-
```
Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
import { describe, it, expect } from 'vitest';
22
import { TestProject } from '../utils';
33

4-
describe.each(['vite-node', 'jiti'] as const)(
5-
'Manifest Content (Vite runtime? %s)',
6-
(entrypointImporter) => {
7-
it.each([
8-
{ browser: undefined, outDir: 'chrome-mv3', expected: undefined },
9-
{ browser: 'chrome', outDir: 'chrome-mv3', expected: undefined },
10-
{ browser: 'firefox', outDir: 'firefox-mv2', expected: true },
11-
{ browser: 'safari', outDir: 'safari-mv2', expected: false },
12-
])(
13-
'should respect the per-browser entrypoint option with %j',
14-
async ({ browser, expected, outDir }) => {
15-
const project = new TestProject();
4+
describe('Manifest Content', () => {
5+
it.each([
6+
{ browser: undefined, outDir: 'chrome-mv3', expected: undefined },
7+
{ browser: 'chrome', outDir: 'chrome-mv3', expected: undefined },
8+
{ browser: 'firefox', outDir: 'firefox-mv2', expected: true },
9+
{ browser: 'safari', outDir: 'safari-mv2', expected: false },
10+
])(
11+
'should respect the per-browser entrypoint option with %j',
12+
async ({ browser, expected, outDir }) => {
13+
const project = new TestProject();
1614

17-
project.addFile(
18-
'entrypoints/background.ts',
19-
`export default defineBackground({
15+
project.addFile(
16+
'entrypoints/background.ts',
17+
`export default defineBackground({
2018
persistent: {
2119
firefox: true,
2220
safari: false,
2321
},
2422
main: () => {},
2523
})`,
26-
);
27-
await project.build({ browser, experimental: { entrypointImporter } });
24+
);
25+
await project.build({ browser });
2826

29-
const safariManifest = await project.getOutputManifest(
30-
`.output/${outDir}/manifest.json`,
31-
);
32-
expect(safariManifest.background.persistent).toBe(expected);
33-
},
34-
);
35-
},
36-
);
27+
const safariManifest = await project.getOutputManifest(
28+
`.output/${outDir}/manifest.json`,
29+
);
30+
expect(safariManifest.background.persistent).toBe(expected);
31+
},
32+
);
33+
});

packages/wxt/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
"giget": "^1.2.3",
101101
"hookable": "^5.5.3",
102102
"is-wsl": "^3.1.0",
103-
"jiti": "^1.21.6",
104103
"json5": "^2.2.3",
105104
"jszip": "^3.10.1",
106105
"linkedom": "^0.18.5",

packages/wxt/src/core/builders/vite/index.ts

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
import { Hookable } from 'hookable';
2121
import { toArray } from '../../utils/arrays';
2222
import { safeVarName } from '../../utils/strings';
23-
import { importEntrypointFile } from '../../utils/building';
2423
import { ViteNodeServer } from 'vite-node/server';
2524
import { ViteNodeRunner } from 'vite-node/client';
2625
import { installSourcemapsSupport } from 'vite-node/source-map';
@@ -280,44 +279,26 @@ export async function createViteBuilder(
280279
version: vite.version,
281280
async importEntrypoint(path) {
282281
const env = createExtensionEnvironment();
283-
switch (wxtConfig.entrypointLoader) {
284-
default:
285-
case 'jiti': {
286-
return await env.run(() => importEntrypointFile(path));
287-
}
288-
case 'vite-node': {
289-
const { runner, server } = await createViteNodeImporter([path]);
290-
const res = await env.run(() => runner.executeFile(path));
291-
await server.close();
292-
requireDefaultExport(path, res);
293-
return res.default;
294-
}
295-
}
282+
const { runner, server } = await createViteNodeImporter([path]);
283+
const res = await env.run(() => runner.executeFile(path));
284+
await server.close();
285+
requireDefaultExport(path, res);
286+
return res.default;
296287
},
297288
async importEntrypoints(paths) {
298289
const env = createExtensionEnvironment();
299-
switch (wxtConfig.entrypointLoader) {
300-
default:
301-
case 'jiti': {
302-
return await env.run(() =>
303-
Promise.all(paths.map(importEntrypointFile)),
304-
);
305-
}
306-
case 'vite-node': {
307-
const { runner, server } = await createViteNodeImporter(paths);
308-
const res = await env.run(() =>
309-
Promise.all(
310-
paths.map(async (path) => {
311-
const mod = await runner.executeFile(path);
312-
requireDefaultExport(path, mod);
313-
return mod.default;
314-
}),
315-
),
316-
);
317-
await server.close();
318-
return res;
319-
}
320-
}
290+
const { runner, server } = await createViteNodeImporter(paths);
291+
const res = await env.run(() =>
292+
Promise.all(
293+
paths.map(async (path) => {
294+
const mod = await runner.executeFile(path);
295+
requireDefaultExport(path, mod);
296+
return mod.default;
297+
}),
298+
),
299+
);
300+
await server.close();
301+
return res;
321302
},
322303
async build(group) {
323304
let entryConfig;

packages/wxt/src/core/resolve-config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ export async function resolveConfig(
201201
analysis: resolveAnalysisConfig(root, mergedConfig),
202202
userConfigMetadata: userConfigMetadata ?? {},
203203
alias,
204-
entrypointLoader: mergedConfig.entrypointLoader ?? 'vite-node',
205204
experimental: defu(mergedConfig.experimental, {}),
206205
dev: {
207206
server: devServerConfig,

packages/wxt/src/core/utils/building/__tests__/import-entrypoint.test.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

packages/wxt/src/core/utils/building/import-entrypoint.ts

Lines changed: 0 additions & 127 deletions
This file was deleted.

packages/wxt/src/core/utils/building/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ export * from './build-entrypoints';
22
export * from './detect-dev-changes';
33
export * from './find-entrypoints';
44
export * from './group-entrypoints';
5-
export * from './import-entrypoint';
65
export * from './internal-build';
76
export * from './rebuild';

0 commit comments

Comments
 (0)