@nullvoxpopuli/ember-vite 1.6.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -6
- package/package.json +2 -2
- package/src/ember.test.ts +133 -11
- package/src/ember.ts +9 -9
package/dist/index.js
CHANGED
|
@@ -139,8 +139,7 @@ function defaultBabelPlugins(mode) {
|
|
|
139
139
|
*
|
|
140
140
|
* Without one (libraries), `defaultBabelPlugins` covers TypeScript, templates, macros, and decorators,
|
|
141
141
|
* so no config file is required.
|
|
142
|
-
*
|
|
143
|
-
* Helpers are inlined in that case:
|
|
142
|
+
* Babel helpers are inlined in that case:
|
|
144
143
|
* projects without a babel config don't carry `@babel/runtime`.
|
|
145
144
|
*/
|
|
146
145
|
function babelOptions(nvpConfig) {
|
|
@@ -152,8 +151,6 @@ function babelOptions(nvpConfig) {
|
|
|
152
151
|
*/
|
|
153
152
|
return {
|
|
154
153
|
configFile: false,
|
|
155
|
-
babelrc: false,
|
|
156
|
-
babelHelpers: "inline",
|
|
157
154
|
plugins: []
|
|
158
155
|
};
|
|
159
156
|
}
|
|
@@ -212,6 +209,7 @@ function babelFilter(nvpConfig) {
|
|
|
212
209
|
function ember(nvpConfig = {}) {
|
|
213
210
|
const babel = babelOptions(nvpConfig);
|
|
214
211
|
const filter = babelFilter(nvpConfig);
|
|
212
|
+
const parallel = nvpConfig.babel?.parallel ?? babel.configFile !== false;
|
|
215
213
|
return [
|
|
216
214
|
{
|
|
217
215
|
name: "ember:nullvoxpopuli",
|
|
@@ -244,7 +242,7 @@ function ember(nvpConfig = {}) {
|
|
|
244
242
|
templateTag(),
|
|
245
243
|
maybeBabel$1({
|
|
246
244
|
...babel,
|
|
247
|
-
parallel
|
|
245
|
+
parallel,
|
|
248
246
|
filter
|
|
249
247
|
})
|
|
250
248
|
];
|
|
@@ -255,7 +253,7 @@ function ember(nvpConfig = {}) {
|
|
|
255
253
|
testHtml(),
|
|
256
254
|
maybeBabel$1({
|
|
257
255
|
...babel,
|
|
258
|
-
parallel
|
|
256
|
+
parallel,
|
|
259
257
|
filter
|
|
260
258
|
})
|
|
261
259
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nullvoxpopuli/ember-vite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Meta plugin for ember projects focusing on speed.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@embroider/core": "^4.6.9",
|
|
22
22
|
"@embroider/macros": "^1.21.3",
|
|
23
23
|
"@embroider/vite": "^1.7.15",
|
|
24
|
-
"@nullvoxpopuli/ember-build-tooling-utils": "
|
|
24
|
+
"@nullvoxpopuli/ember-build-tooling-utils": "2.0.0"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">= 24"
|
package/src/ember.test.ts
CHANGED
|
@@ -94,6 +94,20 @@ const CONTEXT = {
|
|
|
94
94
|
},
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* The babel plugin, after the hooks that rolldown runs before a transform.
|
|
99
|
+
*/
|
|
100
|
+
async function startedBabel(plugins: Plugin[]) {
|
|
101
|
+
const babel = plugins.find((plugin) => plugin.name === "nullvoxpopuli:babel")!;
|
|
102
|
+
|
|
103
|
+
// @ts-expect-error the babel plugin has function hooks
|
|
104
|
+
await babel.buildStart.call(CONTEXT);
|
|
105
|
+
// @ts-expect-error the babel plugin has function hooks
|
|
106
|
+
babel.outputOptions.call({ meta: {} }, {});
|
|
107
|
+
|
|
108
|
+
return babel;
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
/**
|
|
98
112
|
* Runs the config hook, then the babel plugin, the way vite does.
|
|
99
113
|
*/
|
|
@@ -104,7 +118,7 @@ async function compile(mode: string) {
|
|
|
104
118
|
// @ts-expect-error the first entry is the config plugin
|
|
105
119
|
await plugins[0].config.call(ROLLDOWN, config, { command: "build", mode });
|
|
106
120
|
|
|
107
|
-
const babel = plugins
|
|
121
|
+
const babel = await startedBabel(plugins);
|
|
108
122
|
// @ts-expect-error the babel plugin has an object transform hook
|
|
109
123
|
const result = await babel.transform.handler.call(CONTEXT, DEV_CHECK, `${PACKAGE_ROOT}app.js`);
|
|
110
124
|
|
|
@@ -129,22 +143,19 @@ function inPackageRoot() {
|
|
|
129
143
|
}
|
|
130
144
|
|
|
131
145
|
/**
|
|
132
|
-
* A project
|
|
146
|
+
* A project with these files.
|
|
133
147
|
* It is inside this package, so babel resolves its plugins from here.
|
|
134
148
|
*/
|
|
135
|
-
function
|
|
149
|
+
function inProject(files: Record<string, string>) {
|
|
136
150
|
const cache = join(PACKAGE_ROOT, "node_modules/.cache");
|
|
137
151
|
mkdirSync(cache, { recursive: true });
|
|
138
152
|
|
|
139
153
|
const directory = mkdtempSync(join(cache, "project-"));
|
|
140
|
-
const devDependencies = {
|
|
141
|
-
"ember-concurrency": "*",
|
|
142
|
-
"ember-intl": "*",
|
|
143
|
-
"ember-scoped-css": "*",
|
|
144
|
-
"unplugin-icons": "*",
|
|
145
|
-
};
|
|
146
154
|
|
|
147
|
-
|
|
155
|
+
for (const [name, content] of Object.entries(files)) {
|
|
156
|
+
writeFileSync(join(directory, name), content);
|
|
157
|
+
}
|
|
158
|
+
|
|
148
159
|
inDirectory(directory);
|
|
149
160
|
|
|
150
161
|
const restore = restoreCwd!;
|
|
@@ -152,6 +163,22 @@ function inProjectWithLibraries() {
|
|
|
152
163
|
restore();
|
|
153
164
|
rmSync(directory, { recursive: true, force: true });
|
|
154
165
|
};
|
|
166
|
+
|
|
167
|
+
return directory;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A project that depends on the libraries that need babel.
|
|
172
|
+
*/
|
|
173
|
+
function inProjectWithLibraries() {
|
|
174
|
+
const devDependencies = {
|
|
175
|
+
"ember-concurrency": "*",
|
|
176
|
+
"ember-intl": "*",
|
|
177
|
+
"ember-scoped-css": "*",
|
|
178
|
+
"unplugin-icons": "*",
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
inProject({ "package.json": JSON.stringify({ devDependencies }) });
|
|
155
182
|
}
|
|
156
183
|
|
|
157
184
|
describe("default babel plugins", () => {
|
|
@@ -177,6 +204,101 @@ describe("default babel plugins", () => {
|
|
|
177
204
|
});
|
|
178
205
|
});
|
|
179
206
|
|
|
207
|
+
describe("babel config file", () => {
|
|
208
|
+
/**
|
|
209
|
+
* The plugins of a config file are not in the options of `@rolldown/plugin-babel`,
|
|
210
|
+
* and without plugins in its options, that plugin turns itself off in vite.
|
|
211
|
+
*/
|
|
212
|
+
it("keeps babel on in each vite environment", async () => {
|
|
213
|
+
inProject({
|
|
214
|
+
"package.json": `{ "type": "module" }`,
|
|
215
|
+
"babel.config.js": `export default { plugins: [] };`,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const plugins = ember() as Plugin[];
|
|
219
|
+
const babel = plugins.find((plugin) => plugin.name === "nullvoxpopuli:babel")!;
|
|
220
|
+
|
|
221
|
+
// @ts-expect-error the babel plugin has function hooks
|
|
222
|
+
await babel.configResolved.call(CONTEXT, {});
|
|
223
|
+
|
|
224
|
+
// @ts-expect-error the babel plugin has function hooks
|
|
225
|
+
expect(babel.applyToEnvironment.call(CONTEXT, { name: "client" })).toBe(true);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe("babel filter in the dev server", () => {
|
|
230
|
+
/**
|
|
231
|
+
* The vite dev server ignores a filter made of filter expressions,
|
|
232
|
+
* so it gives the babel plugin every module, also the styles of index.html.
|
|
233
|
+
*/
|
|
234
|
+
it("leaves a module outside the filter to oxc", async () => {
|
|
235
|
+
inPackageRoot();
|
|
236
|
+
|
|
237
|
+
const plugins = ember() as Plugin[];
|
|
238
|
+
|
|
239
|
+
// @ts-expect-error the first entry is the config plugin
|
|
240
|
+
await plugins[0].config.call(ROLLDOWN, {}, { command: "serve", mode: "development" });
|
|
241
|
+
|
|
242
|
+
const babel = await startedBabel(plugins);
|
|
243
|
+
const styles = `${PACKAGE_ROOT}index.html?html-proxy&direct&index=0.css`;
|
|
244
|
+
|
|
245
|
+
// @ts-expect-error the babel plugin has an object transform hook
|
|
246
|
+
const result = await babel.transform.handler.call(CONTEXT, `:root { color: red; }`, styles);
|
|
247
|
+
|
|
248
|
+
expect(result).toBeUndefined();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe("babel.parallel", () => {
|
|
253
|
+
/**
|
|
254
|
+
* A babel plugin that writes which thread compiled the file.
|
|
255
|
+
*/
|
|
256
|
+
const THREAD_PLUGIN = [
|
|
257
|
+
`import { isMainThread } from "node:worker_threads";`,
|
|
258
|
+
`export default ({ types: t }) => ({`,
|
|
259
|
+
` visitor: {`,
|
|
260
|
+
` Program(path) {`,
|
|
261
|
+
` const thread = isMainThread ? "main thread" : "worker thread";`,
|
|
262
|
+
` path.unshiftContainer("body", t.expressionStatement(t.stringLiteral(thread)));`,
|
|
263
|
+
` },`,
|
|
264
|
+
` },`,
|
|
265
|
+
`});`,
|
|
266
|
+
].join("\n");
|
|
267
|
+
|
|
268
|
+
async function compileWithConfigFile(options: Parameters<typeof ember>[0] = {}) {
|
|
269
|
+
const directory = inProject({
|
|
270
|
+
"package.json": `{ "type": "module" }`,
|
|
271
|
+
"thread-plugin.js": THREAD_PLUGIN,
|
|
272
|
+
"babel.config.js": `export default { plugins: ["./thread-plugin.js"] };`,
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
const plugins = ember(options) as Plugin[];
|
|
276
|
+
const babel = await startedBabel(plugins);
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
// @ts-expect-error the babel plugin has an object transform hook
|
|
280
|
+
const result = await babel.transform.handler.call(
|
|
281
|
+
CONTEXT,
|
|
282
|
+
`import { macroCondition } from "@embroider/macros";`,
|
|
283
|
+
join(directory, "app/a.js"),
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
return result.code as string;
|
|
287
|
+
} finally {
|
|
288
|
+
// @ts-expect-error the babel plugin ends its workers in closeBundle
|
|
289
|
+
await babel.closeBundle.call({ meta: { watchMode: false } });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
it("runs babel in worker threads when the project has a babel config file", async () => {
|
|
294
|
+
expect(await compileWithConfigFile()).toContain("worker thread");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("runs babel in the main thread when parallel is false", async () => {
|
|
298
|
+
expect(await compileWithConfigFile({ babel: { parallel: false } })).toContain("main thread");
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
180
302
|
/**
|
|
181
303
|
* The module that unplugin-icons gives for an icon, with `compiler: "ember"`.
|
|
182
304
|
*/
|
|
@@ -294,7 +416,7 @@ describe("libraries that need babel", () => {
|
|
|
294
416
|
// @ts-expect-error the first entry is the config plugin
|
|
295
417
|
await plugins[0].config.call(ROLLDOWN, config, { command: "build", mode: "production" });
|
|
296
418
|
|
|
297
|
-
const babel = plugins
|
|
419
|
+
const babel = await startedBabel(plugins);
|
|
298
420
|
// @ts-expect-error the babel plugin has an object transform hook
|
|
299
421
|
const result = await babel.transform.handler.call(CONTEXT, ICON, "~icons/lucide/check");
|
|
300
422
|
|
package/src/ember.ts
CHANGED
|
@@ -93,8 +93,6 @@ type BabelOptions =
|
|
|
93
93
|
| { configFile: string }
|
|
94
94
|
| {
|
|
95
95
|
configFile: false;
|
|
96
|
-
babelrc: false;
|
|
97
|
-
babelHelpers: "inline";
|
|
98
96
|
plugins: ReturnType<typeof defaultBabelPlugins>;
|
|
99
97
|
};
|
|
100
98
|
|
|
@@ -104,8 +102,7 @@ type BabelOptions =
|
|
|
104
102
|
*
|
|
105
103
|
* Without one (libraries), `defaultBabelPlugins` covers TypeScript, templates, macros, and decorators,
|
|
106
104
|
* so no config file is required.
|
|
107
|
-
*
|
|
108
|
-
* Helpers are inlined in that case:
|
|
105
|
+
* Babel helpers are inlined in that case:
|
|
109
106
|
* projects without a babel config don't carry `@babel/runtime`.
|
|
110
107
|
*/
|
|
111
108
|
function babelOptions(nvpConfig: Config): BabelOptions {
|
|
@@ -123,8 +120,6 @@ function babelOptions(nvpConfig: Config): BabelOptions {
|
|
|
123
120
|
*/
|
|
124
121
|
return {
|
|
125
122
|
configFile: false,
|
|
126
|
-
babelrc: false,
|
|
127
|
-
babelHelpers: "inline",
|
|
128
123
|
plugins: [],
|
|
129
124
|
};
|
|
130
125
|
}
|
|
@@ -195,8 +190,12 @@ function babelFilter(nvpConfig: Config) {
|
|
|
195
190
|
interface Config {
|
|
196
191
|
babel?: {
|
|
197
192
|
/**
|
|
198
|
-
* defaults to true.
|
|
199
193
|
* when babel runs, do so in parallel across many cores.
|
|
194
|
+
*
|
|
195
|
+
* defaults to true when the project has a babel config file.
|
|
196
|
+
* Without one, babel stays in the main thread:
|
|
197
|
+
* the default plugins carry functions,
|
|
198
|
+
* and a worker thread cannot receive functions.
|
|
200
199
|
*/
|
|
201
200
|
parallel?: false;
|
|
202
201
|
|
|
@@ -256,6 +255,7 @@ interface Config {
|
|
|
256
255
|
export function ember(nvpConfig: Config = {}) {
|
|
257
256
|
const babel = babelOptions(nvpConfig);
|
|
258
257
|
const filter = babelFilter(nvpConfig);
|
|
258
|
+
const parallel = nvpConfig.babel?.parallel ?? babel.configFile !== false;
|
|
259
259
|
|
|
260
260
|
/*
|
|
261
261
|
* Plugins must be returned as top-level array entries,
|
|
@@ -317,7 +317,7 @@ export function ember(nvpConfig: Config = {}) {
|
|
|
317
317
|
// Both must compile away here, with this app's template compiler.
|
|
318
318
|
maybeBabel({
|
|
319
319
|
...babel,
|
|
320
|
-
parallel
|
|
320
|
+
parallel,
|
|
321
321
|
filter,
|
|
322
322
|
}),
|
|
323
323
|
];
|
|
@@ -328,7 +328,7 @@ export function ember(nvpConfig: Config = {}) {
|
|
|
328
328
|
testHtml(),
|
|
329
329
|
maybeBabel({
|
|
330
330
|
...babel,
|
|
331
|
-
parallel
|
|
331
|
+
parallel,
|
|
332
332
|
filter,
|
|
333
333
|
}),
|
|
334
334
|
];
|