@nullvoxpopuli/ember-vite 1.4.0 → 1.5.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/README.md +1 -0
- package/dist/index.js +5 -1
- package/package.json +2 -1
- package/src/ember.test.ts +37 -0
- package/src/ember.ts +17 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -175,7 +175,11 @@ function babelFilter(nvpConfig) {
|
|
|
175
175
|
"ember-intl/helpers/format-message",
|
|
176
176
|
...nvpConfig.babel?.include?.whenImporting ?? []
|
|
177
177
|
],
|
|
178
|
-
code: [
|
|
178
|
+
code: [
|
|
179
|
+
/\bintl\.formatMessage\b/,
|
|
180
|
+
"initializeRuntimeMacrosConfig",
|
|
181
|
+
...nvpConfig.babel?.include?.whenMatching ?? []
|
|
182
|
+
]
|
|
179
183
|
} };
|
|
180
184
|
}
|
|
181
185
|
function ember(nvpConfig = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nullvoxpopuli/ember-vite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Meta plugin for ember projects focusing on speed.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/plugin-transform-typescript": "^7.28.10 || ^8.0.0",
|
|
31
|
+
"@rolldown/pluginutils": "^1.0.1",
|
|
31
32
|
"babel-plugin-ember-template-compilation": "^4.0.1",
|
|
32
33
|
"decorator-transforms": "^2.4.0",
|
|
33
34
|
"rolldown": "^1.1.2",
|
package/src/ember.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { extensions } from "@embroider/vite";
|
|
2
|
+
import { interpreter, type TopLevelFilterExpression } from "@rolldown/pluginutils";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
import type { ConfigEnv, ConfigPluginContext, Plugin } from "vite";
|
|
4
5
|
import { afterEach, describe, expect, it } from "vitest";
|
|
@@ -143,3 +144,39 @@ describe("default babel plugins", () => {
|
|
|
143
144
|
expect(code).toContain("other build");
|
|
144
145
|
});
|
|
145
146
|
});
|
|
147
|
+
|
|
148
|
+
describe("babel.include", () => {
|
|
149
|
+
function usesBabel(options: Parameters<typeof ember>[0], source: string) {
|
|
150
|
+
const plugins = ember(options) as Plugin[];
|
|
151
|
+
const babel = plugins.find((plugin) => plugin.name === "nullvoxpopuli:babel");
|
|
152
|
+
// @ts-expect-error maybeBabel sets the filter on the transform hook
|
|
153
|
+
const filter = babel.transform.filter as TopLevelFilterExpression[];
|
|
154
|
+
|
|
155
|
+
return interpreter(filter, source, "/app/services/a.ts");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const source = `owner.register(Key, Impl);`;
|
|
159
|
+
|
|
160
|
+
it("leaves files without a babel-only pattern to oxc", () => {
|
|
161
|
+
expect(usesBabel({}, source)).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("sends files that contain a whenMatching string to babel", () => {
|
|
165
|
+
expect(usesBabel({ babel: { include: { whenMatching: [".register("] } } }, source)).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("sends files that match a whenMatching regular expression to babel", () => {
|
|
169
|
+
expect(usesBabel({ babel: { include: { whenMatching: [/\.register\(/] } } }, source)).toBe(
|
|
170
|
+
true,
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("sends files that import a whenImporting module to babel", () => {
|
|
175
|
+
expect(
|
|
176
|
+
usesBabel(
|
|
177
|
+
{ babel: { include: { whenImporting: ["my-lib"] } } },
|
|
178
|
+
`import { a } from "my-lib";`,
|
|
179
|
+
),
|
|
180
|
+
).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
});
|
package/src/ember.ts
CHANGED
|
@@ -148,7 +148,11 @@ function babelFilter(nvpConfig: Config) {
|
|
|
148
148
|
"ember-intl/helpers/format-message",
|
|
149
149
|
...(nvpConfig.babel?.include?.whenImporting ?? []),
|
|
150
150
|
],
|
|
151
|
-
code: [
|
|
151
|
+
code: [
|
|
152
|
+
/\bintl\.formatMessage\b/,
|
|
153
|
+
"initializeRuntimeMacrosConfig",
|
|
154
|
+
...(nvpConfig.babel?.include?.whenMatching ?? []),
|
|
155
|
+
] as (string | RegExp)[],
|
|
152
156
|
},
|
|
153
157
|
};
|
|
154
158
|
}
|
|
@@ -185,6 +189,18 @@ interface Config {
|
|
|
185
189
|
* For example: ['ember-concurrency'],
|
|
186
190
|
*/
|
|
187
191
|
whenImporting?: (string | "ember-concurrency" | "ember-scoped-css")[];
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* if a file's source contains any of these strings,
|
|
195
|
+
* or matches any of these regular expressions,
|
|
196
|
+
* use babel instead of oxc for that file.
|
|
197
|
+
*
|
|
198
|
+
* Use this for babel plugins that look for a code pattern rather than
|
|
199
|
+
* an import.
|
|
200
|
+
*
|
|
201
|
+
* For example: [/\.register\(/],
|
|
202
|
+
*/
|
|
203
|
+
whenMatching?: (string | RegExp)[];
|
|
188
204
|
};
|
|
189
205
|
};
|
|
190
206
|
/**
|