@embroider/vite 0.2.1 → 0.2.2-unstable.01e21e6

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/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from './src/resolver.js';
2
+ export * from './src/esbuild-resolver.js';
2
3
  export * from './src/hbs.js';
3
4
  export * from './src/scripts.js';
4
5
  export * from './src/template-tag.js';
5
- export * from './src/addons.js';
6
6
  export * from './src/optimize-deps.js';
7
+ export * from './src/assets.js';
8
+ export * from './src/build.js';
9
+ export * from './src/content-for.js';
package/index.mjs CHANGED
@@ -1,6 +1,11 @@
1
1
  export * from './src/resolver.js';
2
+ export * from './src/esbuild-resolver.js';
2
3
  export * from './src/hbs.js';
3
4
  export * from './src/scripts.js';
4
5
  export * from './src/template-tag.js';
5
- export * from './src/addons.js';
6
6
  export * from './src/optimize-deps.js';
7
+ export * from './src/build.js';
8
+ export * from './src/assets.js';
9
+ export * from './src/content-for.js';
10
+ export * from './src/classic-ember-support.js';
11
+ export * from './src/ember.js';
package/package.json CHANGED
@@ -1,28 +1,44 @@
1
1
  {
2
2
  "name": "@embroider/vite",
3
- "version": "0.2.1",
4
- "main": "index.mjs",
3
+ "version": "0.2.2-unstable.01e21e6",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "default": "./index.mjs",
8
+ "types": "./index.d.ts"
9
+ }
10
+ },
5
11
  "peerDependencies": {
6
- "vite": "^4.3.9",
7
- "@embroider/core": "^3.4.17"
12
+ "vite": "^5.2.0",
13
+ "@embroider/core": "^3.4.20-unstable.01e21e6"
8
14
  },
9
15
  "dependencies": {
10
- "@rollup/pluginutils": "^4.1.1",
16
+ "@babel/core": "^7.22.9",
17
+ "@rollup/pluginutils": "^5.1.0",
11
18
  "assert-never": "^1.2.1",
12
- "content-tag": "^2.0.1",
19
+ "browserslist": "*",
20
+ "browserslist-to-esbuild": "^2.1.1",
21
+ "content-tag": "^2.0.2",
13
22
  "debug": "^4.3.2",
23
+ "esbuild": "^0.17.19",
24
+ "fast-glob": "^3.3.2",
14
25
  "fs-extra": "^10.0.0",
15
26
  "jsdom": "^25.0.0",
27
+ "send": "^0.18.0",
16
28
  "source-map-url": "^0.4.1",
17
- "terser": "^5.7.0"
29
+ "terser": "^5.7.0",
30
+ "@embroider/macros": "1.16.10-unstable.01e21e6",
31
+ "@embroider/reverse-exports": "0.1.1-unstable.01e21e6"
18
32
  },
19
33
  "devDependencies": {
34
+ "@types/babel__core": "^7.20.1",
20
35
  "@types/debug": "^4.1.5",
21
- "@types/jsdom": "^16.2.11",
22
36
  "@types/fs-extra": "^9.0.12",
23
- "rollup": "^3.23.0",
24
- "vite": "^4.3.9",
25
- "@embroider/core": "^3.4.17"
37
+ "@types/jsdom": "^16.2.11",
38
+ "@types/send": "^0.17.4",
39
+ "rollup": "^4.18.0",
40
+ "vite": "^5.3.3",
41
+ "@embroider/core": "^3.4.20-unstable.01e21e6"
26
42
  },
27
43
  "files": [
28
44
  "index.mjs",
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function assets(): Plugin;
package/src/assets.js ADDED
@@ -0,0 +1,87 @@
1
+ import core from '@embroider/core';
2
+ const { ResolverLoader } = core;
3
+ import * as process from 'process';
4
+ import { join, posix } from 'path';
5
+ import fs from 'fs-extra';
6
+ const { existsSync, readFileSync, lstatSync } = fs;
7
+ import send from 'send';
8
+ function findPublicAsset(relativePath, resolver) {
9
+ var _a;
10
+ const packageCache = resolver.packageCache;
11
+ let pkg = packageCache.ownerOfFile(relativePath);
12
+ for (const engine of resolver.options.engines) {
13
+ for (const addon of engine.activeAddons) {
14
+ pkg = packageCache.ownerOfFile(addon.root);
15
+ if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) {
16
+ const asset = (_a = Object.entries(pkg.meta['public-assets']).find(([_key, a]) => posix.resolve('/', a) === relativePath)) === null || _a === void 0 ? void 0 : _a[0];
17
+ let local = asset ? join(addon.root, asset) : null;
18
+ if (local && existsSync(local)) {
19
+ return local;
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
25
+ export function assets() {
26
+ const cwd = process.cwd();
27
+ const resolverLoader = new ResolverLoader(cwd);
28
+ let mode = 'build';
29
+ let publicDir = 'public';
30
+ return {
31
+ name: 'assets',
32
+ enforce: 'post',
33
+ configResolved(options) {
34
+ mode = options.command;
35
+ publicDir = options.publicDir;
36
+ },
37
+ configureServer(server) {
38
+ return () => {
39
+ server.middlewares.use((req, res, next) => {
40
+ if (req.originalUrl && req.originalUrl.length > 1) {
41
+ const assetUrl = findPublicAsset(req.originalUrl.split('?')[0], resolverLoader.resolver);
42
+ if (assetUrl) {
43
+ return send(req, assetUrl).pipe(res);
44
+ }
45
+ }
46
+ return next();
47
+ });
48
+ };
49
+ },
50
+ buildStart: {
51
+ // we need to wait for the compatBuild plugin's buildStart hook to finish
52
+ // so that the resolver config exists before we try to read it.
53
+ sequential: true,
54
+ order: 'post',
55
+ async handler() {
56
+ if (mode !== 'build')
57
+ return;
58
+ const engines = resolverLoader.resolver.options.engines;
59
+ for (const engine of engines) {
60
+ const packages = engine.activeAddons.map(a => resolverLoader.resolver.packageCache.ownerOfFile(a.root));
61
+ packages.forEach(pkg => {
62
+ if (!pkg || !pkg.isV2Addon())
63
+ return;
64
+ const assets = pkg.meta['public-assets'] || {};
65
+ Object.entries(assets).forEach(([path, dest]) => {
66
+ // do not override app public assets
67
+ if (existsSync(join(publicDir, dest))) {
68
+ return;
69
+ }
70
+ const filePath = join(pkg.root, path);
71
+ if (!lstatSync(filePath).isFile()) {
72
+ console.log(`Invalid package definition, ${pkg.name} has defined a file "${path}" that is not a file`);
73
+ return;
74
+ }
75
+ this.emitFile({
76
+ type: 'asset',
77
+ source: readFileSync(filePath),
78
+ fileName: posix.resolve('/', dest).slice(1),
79
+ });
80
+ });
81
+ });
82
+ }
83
+ },
84
+ },
85
+ };
86
+ }
87
+ //# sourceMappingURL=assets.js.map
@@ -0,0 +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9B,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;6BAC5C,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Resolver } from '@embroider/core';\nimport core from '@embroider/core';\nconst { ResolverLoader } = core;\nimport type { Plugin } from 'vite';\nimport * as process from 'process';\nimport { join, posix } from 'path';\nimport fs from 'fs-extra';\nconst { existsSync, readFileSync, lstatSync } = fs;\nimport send from 'send';\n\nfunction findPublicAsset(relativePath: string, resolver: Resolver) {\n const packageCache = resolver.packageCache;\n let pkg = packageCache.ownerOfFile(relativePath);\n\n for (const engine of resolver.options.engines) {\n for (const addon of engine.activeAddons) {\n pkg = packageCache.ownerOfFile(addon.root);\n if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) {\n const asset = Object.entries(pkg.meta['public-assets']).find(\n ([_key, a]) => posix.resolve('/', a) === relativePath\n )?.[0];\n let local = asset ? join(addon.root, asset) : null;\n if (local && existsSync(local)) {\n return local;\n }\n }\n }\n }\n}\n\nexport function assets(): Plugin {\n const cwd = process.cwd();\n const resolverLoader = new ResolverLoader(cwd);\n let mode: 'build' | 'serve' = 'build';\n let publicDir = 'public';\n return {\n name: 'assets',\n enforce: 'post',\n configResolved(options) {\n mode = options.command;\n publicDir = options.publicDir;\n },\n configureServer(server) {\n return () => {\n server.middlewares.use((req, res, next) => {\n if (req.originalUrl && req.originalUrl.length > 1) {\n const assetUrl = findPublicAsset(req.originalUrl.split('?')[0], resolverLoader.resolver);\n if (assetUrl) {\n return send(req, assetUrl).pipe(res as unknown as NodeJS.WritableStream);\n }\n }\n return next();\n });\n };\n },\n buildStart: {\n // we need to wait for the compatBuild plugin's buildStart hook to finish\n // so that the resolver config exists before we try to read it.\n sequential: true,\n order: 'post',\n async handler() {\n if (mode !== 'build') return;\n const engines = resolverLoader.resolver.options.engines;\n for (const engine of engines) {\n const packages = engine.activeAddons.map(a => resolverLoader.resolver.packageCache.ownerOfFile(a.root));\n packages.forEach(pkg => {\n if (!pkg || !pkg.isV2Addon()) return;\n const assets = pkg.meta['public-assets'] || {};\n Object.entries(assets).forEach(([path, dest]) => {\n // do not override app public assets\n if (existsSync(join(publicDir, dest))) {\n return;\n }\n\n const filePath = join(pkg.root, path);\n if (!lstatSync(filePath).isFile()) {\n console.log(`Invalid package definition, ${pkg.name} has defined a file \"${path}\" that is not a file`);\n return;\n }\n\n this.emitFile({\n type: 'asset',\n source: readFileSync(filePath),\n fileName: posix.resolve('/', dest).slice(1),\n });\n });\n });\n }\n },\n },\n };\n}\n"]}
package/src/build.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function emberBuild(command: string, mode: string, resolvableExtensions: string[] | undefined): Promise<void>;
3
+ export declare function compatPrebuild(): Plugin;
package/src/build.js ADDED
@@ -0,0 +1,60 @@
1
+ import { fork } from 'child_process';
2
+ export function emberBuild(command, mode, resolvableExtensions) {
3
+ let env = {
4
+ ...process.env,
5
+ EMBROIDER_PREBUILD: 'true',
6
+ };
7
+ if (resolvableExtensions) {
8
+ env['EMBROIDER_RESOLVABLE_EXTENSIONS'] = resolvableExtensions === null || resolvableExtensions === void 0 ? void 0 : resolvableExtensions.join(',');
9
+ }
10
+ if (command === 'build') {
11
+ return new Promise((resolve, reject) => {
12
+ const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--environment', mode, '-o', 'tmp/compat-prebuild', '--suppress-sizes'], { env });
13
+ child.on('exit', code => (code === 0 ? resolve() : reject()));
14
+ });
15
+ }
16
+ return new Promise((resolve, reject) => {
17
+ const child = fork('./node_modules/ember-cli/bin/ember', ['build', '--watch', '--environment', mode, '-o', 'tmp/compat-prebuild', '--suppress-sizes'], {
18
+ silent: true,
19
+ env,
20
+ });
21
+ child.on('exit', code => (code === 0 ? resolve() : reject(new Error('ember build --watch failed'))));
22
+ child.on('spawn', () => {
23
+ var _a;
24
+ (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', data => {
25
+ console.error(data.toString());
26
+ });
27
+ child.stdout.on('data', data => {
28
+ console.log(data.toString());
29
+ if (data.toString().includes('Build successful')) {
30
+ resolve();
31
+ }
32
+ });
33
+ });
34
+ });
35
+ }
36
+ export function compatPrebuild() {
37
+ let viteCommand;
38
+ let viteMode;
39
+ let resolvableExtensions;
40
+ return {
41
+ name: 'embroider-builder',
42
+ enforce: 'pre',
43
+ config(config, { mode, command }) {
44
+ var _a;
45
+ viteCommand = command;
46
+ viteMode = mode;
47
+ resolvableExtensions = (_a = config.resolve) === null || _a === void 0 ? void 0 : _a.extensions;
48
+ },
49
+ async buildStart() {
50
+ if (!viteCommand) {
51
+ throw new Error(`bug: embroider compatPrebuild did not detect Vite's command`);
52
+ }
53
+ if (!viteMode) {
54
+ throw new Error(`bug: embroider compatPrebuild did not detect Vite's mode`);
55
+ }
56
+ await emberBuild(viteCommand, viteMode, resolvableExtensions);
57
+ },
58
+ };
59
+ }
60
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAGrC,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,IAAY,EAAE,oBAA0C;IAClG,IAAI,GAAG,GAA2B;QAChC,GAAG,OAAO,CAAC,GAAG;QACd,kBAAkB,EAAE,MAAM;KAC3B,CAAC;IAEF,IAAI,oBAAoB,EAAE,CAAC;QACzB,GAAG,CAAC,iCAAiC,CAAC,GAAG,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,IAAI,OAAO,CAAC,CAAC,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,CAAC,CAAC;gBAC7B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;oBACjD,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,IAAI,WAA+B,CAAC;IACpC,IAAI,QAA4B,CAAC;IACjC,IAAI,oBAA0C,CAAC;IAE/C,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,KAAK;QACd,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;;YAC9B,WAAW,GAAG,OAAO,CAAC;YACtB,QAAQ,GAAG,IAAI,CAAC;YAChB,oBAAoB,GAAG,MAAA,MAAM,CAAC,OAAO,0CAAE,UAAU,CAAC;QACpD,CAAC;QACD,KAAK,CAAC,UAAU;YACd,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;YACjF,CAAC;YACD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAC9E,CAAC;YACD,MAAM,UAAU,CAAC,WAAW,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC;QAChE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { fork } from 'child_process';\nimport type { Plugin } from 'vite';\n\nexport function emberBuild(command: string, mode: string, resolvableExtensions: string[] | undefined): Promise<void> {\n let env: Record<string, string> = {\n ...process.env,\n EMBROIDER_PREBUILD: 'true',\n };\n\n if (resolvableExtensions) {\n env['EMBROIDER_RESOLVABLE_EXTENSIONS'] = resolvableExtensions?.join(',');\n }\n\n if (command === 'build') {\n return new Promise((resolve, reject) => {\n const child = fork(\n './node_modules/ember-cli/bin/ember',\n ['build', '--environment', mode, '-o', 'tmp/compat-prebuild', '--suppress-sizes'],\n { env }\n );\n child.on('exit', code => (code === 0 ? resolve() : reject()));\n });\n }\n return new Promise((resolve, reject) => {\n const child = fork(\n './node_modules/ember-cli/bin/ember',\n ['build', '--watch', '--environment', mode, '-o', 'tmp/compat-prebuild', '--suppress-sizes'],\n {\n silent: true,\n env,\n }\n );\n child.on('exit', code => (code === 0 ? resolve() : reject(new Error('ember build --watch failed'))));\n child.on('spawn', () => {\n child.stderr?.on('data', data => {\n console.error(data.toString());\n });\n child.stdout!.on('data', data => {\n console.log(data.toString());\n if (data.toString().includes('Build successful')) {\n resolve();\n }\n });\n });\n });\n}\n\nexport function compatPrebuild(): Plugin {\n let viteCommand: string | undefined;\n let viteMode: string | undefined;\n let resolvableExtensions: string[] | undefined;\n\n return {\n name: 'embroider-builder',\n enforce: 'pre',\n config(config, { mode, command }) {\n viteCommand = command;\n viteMode = mode;\n resolvableExtensions = config.resolve?.extensions;\n },\n async buildStart() {\n if (!viteCommand) {\n throw new Error(`bug: embroider compatPrebuild did not detect Vite's command`);\n }\n if (!viteMode) {\n throw new Error(`bug: embroider compatPrebuild did not detect Vite's mode`);\n }\n await emberBuild(viteCommand, viteMode, resolvableExtensions);\n },\n };\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { type UserConfig } from 'vite';
2
+ export declare function classicEmberSupport(): (import("vite").Plugin<any> | {
3
+ name: string;
4
+ config(userConfig: UserConfig): Promise<Record<string, any> | UserConfig>;
5
+ })[];
@@ -0,0 +1,37 @@
1
+ import { hbs } from './hbs.js';
2
+ import { scripts } from './scripts.js';
3
+ import { compatPrebuild } from './build.js';
4
+ import { assets } from './assets.js';
5
+ import { contentFor } from './content-for.js';
6
+ import browserslistToEsbuild from 'browserslist-to-esbuild';
7
+ import { existsSync } from 'fs';
8
+ import { join } from 'path';
9
+ import { mergeConfig } from 'vite';
10
+ import { pathToFileURL } from 'url';
11
+ export function classicEmberSupport() {
12
+ return [
13
+ hbs(),
14
+ scripts(),
15
+ compatPrebuild(),
16
+ assets(),
17
+ contentFor(),
18
+ {
19
+ name: 'vite-plugin-ember-browser-targets',
20
+ async config(userConfig) {
21
+ const targetsPath = join(process.cwd(), 'config/targets.js');
22
+ if (existsSync(targetsPath)) {
23
+ const targets = await import(pathToFileURL(targetsPath).toString());
24
+ if (targets.default.browsers) {
25
+ return mergeConfig({
26
+ build: {
27
+ target: browserslistToEsbuild(targets.browsers),
28
+ },
29
+ }, userConfig);
30
+ }
31
+ }
32
+ return userConfig;
33
+ },
34
+ },
35
+ ];
36
+ }
37
+ //# sourceMappingURL=classic-ember-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classic-ember-support.js","sourceRoot":"","sources":["classic-ember-support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAmB,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,GAAG,EAAE;QACL,OAAO,EAAE;QACT,cAAc,EAAE;QAChB,MAAM,EAAE;QACR,UAAU,EAAE;QACZ;YACE,IAAI,EAAE,mCAAmC;YACzC,KAAK,CAAC,MAAM,CAAC,UAAsB;gBACjC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC,CAAC;gBAC7D,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;oBAC5B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;oBACpE,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;wBAC7B,OAAO,WAAW,CAChB;4BACE,KAAK,EAAE;gCACL,MAAM,EAAE,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC;6BAChD;yBACF,EACD,UAAU,CACX,CAAC;oBACJ,CAAC;gBACH,CAAC;gBACD,OAAO,UAAU,CAAC;YACpB,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { hbs } from './hbs.js';\nimport { scripts } from './scripts.js';\nimport { compatPrebuild } from './build.js';\nimport { assets } from './assets.js';\nimport { contentFor } from './content-for.js';\nimport browserslistToEsbuild from 'browserslist-to-esbuild';\nimport { existsSync } from 'fs';\nimport { join } from 'path';\nimport { mergeConfig, type UserConfig } from 'vite';\nimport { pathToFileURL } from 'url';\n\nexport function classicEmberSupport() {\n return [\n hbs(),\n scripts(),\n compatPrebuild(),\n assets(),\n contentFor(),\n {\n name: 'vite-plugin-ember-browser-targets',\n async config(userConfig: UserConfig) {\n const targetsPath = join(process.cwd(), 'config/targets.js');\n if (existsSync(targetsPath)) {\n const targets = await import(pathToFileURL(targetsPath).toString());\n if (targets.default.browsers) {\n return mergeConfig(\n {\n build: {\n target: browserslistToEsbuild(targets.browsers),\n },\n },\n userConfig\n );\n }\n }\n return userConfig;\n },\n },\n ];\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function contentFor(): Plugin;
@@ -0,0 +1,19 @@
1
+ import fs from 'fs-extra';
2
+ const { readJSONSync } = fs;
3
+ import { join } from 'path';
4
+ import core from '@embroider/core';
5
+ const { locateEmbroiderWorkingDir } = core;
6
+ export function contentFor() {
7
+ return {
8
+ name: 'embroider-content-for',
9
+ transformIndexHtml(html, { path }) {
10
+ let config = readJSONSync(join(locateEmbroiderWorkingDir(process.cwd()), 'content-for.json'));
11
+ let contentsForConfig = config[path];
12
+ for (const [contentType, htmlContent] of Object.entries(contentsForConfig)) {
13
+ html = html.replace(`{{content-for "${contentType}"}}`, `${htmlContent}`);
14
+ }
15
+ return html;
16
+ },
17
+ };
18
+ }
19
+ //# sourceMappingURL=content-for.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-for.js","sourceRoot":"","sources":["content-for.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,yBAAyB,EAAE,GAAG,IAAI,CAAC;AAE3C,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,IAAI,EAAE,uBAAuB;QAE7B,kBAAkB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE;YAC/B,IAAI,MAAM,GAAQ,YAAY,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;YACnG,IAAI,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YACrC,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAC3E,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,WAAW,KAAK,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;YAC5E,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from 'vite';\nimport fs from 'fs-extra';\nconst { readJSONSync } = fs;\nimport { join } from 'path';\nimport core from '@embroider/core';\nconst { locateEmbroiderWorkingDir } = core;\n\nexport function contentFor(): Plugin {\n return {\n name: 'embroider-content-for',\n\n transformIndexHtml(html, { path }) {\n let config: any = readJSONSync(join(locateEmbroiderWorkingDir(process.cwd()), 'content-for.json'));\n let contentsForConfig = config[path];\n for (const [contentType, htmlContent] of Object.entries(contentsForConfig)) {\n html = html.replace(`{{content-for \"${contentType}\"}}`, `${htmlContent}`);\n }\n return html;\n },\n };\n}\n"]}
package/src/ember.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { type UserConfig, type ConfigEnv } from 'vite';
2
+ export declare let extensions: string[];
3
+ export declare function ember(): (import("vite").Plugin<any> | {
4
+ name: string;
5
+ config(config: UserConfig, env: ConfigEnv): Promise<Record<string, any>>;
6
+ })[];
package/src/ember.js ADDED
@@ -0,0 +1,43 @@
1
+ import { templateTag } from './template-tag.js';
2
+ import { resolver } from './resolver.js';
3
+ import { mergeConfig } from 'vite';
4
+ import { esBuildResolver } from './esbuild-resolver.js';
5
+ export let extensions = ['.mjs', '.gjs', '.js', '.mts', '.gts', '.ts', '.hbs', '.hbs.js', '.json'];
6
+ export function ember() {
7
+ return [
8
+ templateTag(),
9
+ resolver(),
10
+ {
11
+ name: 'vite-plugin-ember-config',
12
+ async config(config, env) {
13
+ return mergeConfig({
14
+ resolve: {
15
+ extensions,
16
+ },
17
+ optimizeDeps: {
18
+ exclude: ['@embroider/macros'],
19
+ extensions: ['.hbs', '.gjs', '.gts'],
20
+ esbuildOptions: {
21
+ plugins: [esBuildResolver()],
22
+ },
23
+ },
24
+ build: {
25
+ rollupOptions: {
26
+ input: {
27
+ main: 'index.html',
28
+ ...(shouldBuildTests(env.mode) ? { tests: 'tests/index.html' } : undefined),
29
+ },
30
+ },
31
+ },
32
+ server: {
33
+ port: 4200,
34
+ },
35
+ }, config);
36
+ },
37
+ },
38
+ ];
39
+ }
40
+ function shouldBuildTests(mode) {
41
+ return mode !== 'production' || process.env.FORCE_BUILD_TESTS;
42
+ }
43
+ //# source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AAC,IAAY;IACpC,OAAO,IAAI,KAAK,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAChE,CAAC","sourcesContent":["import { templateTag } from './template-tag.js';\nimport { resolver } from './resolver.js';\nimport { mergeConfig, type UserConfig, type ConfigEnv } from 'vite';\nimport { esBuildResolver } from './esbuild-resolver.js';\n\nexport let extensions = ['.mjs', '.gjs', '.js', '.mts', '.gts', '.ts', '.hbs', '.hbs.js', '.json'];\n\nexport function ember() {\n return [\n templateTag(),\n resolver(),\n {\n name: 'vite-plugin-ember-config',\n async config(config: UserConfig, env: ConfigEnv) {\n return mergeConfig(\n {\n resolve: {\n extensions,\n },\n\n optimizeDeps: {\n exclude: ['@embroider/macros'],\n extensions: ['.hbs', '.gjs', '.gts'],\n esbuildOptions: {\n plugins: [esBuildResolver()],\n },\n },\n\n build: {\n rollupOptions: {\n input: {\n main: 'index.html',\n ...(shouldBuildTests(env.mode) ? { tests: 'tests/index.html' } : undefined),\n },\n },\n },\n server: {\n port: 4200,\n },\n },\n config\n );\n },\n },\n ];\n}\n\nfunction shouldBuildTests(mode: string) {\n return mode !== 'production' || process.env.FORCE_BUILD_TESTS;\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import core from '@embroider/core';
2
+ import type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';
3
+ import type { PackageCache as _PackageCache, Resolution, ModuleRequest, RequestAdapter } from '@embroider/core';
4
+ type PublicAPI<T> = {
5
+ [K in keyof T]: T[K];
6
+ };
7
+ type PackageCache = PublicAPI<_PackageCache>;
8
+ export declare class EsBuildRequestAdapter implements RequestAdapter<Resolution<OnResolveResult, OnResolveResult>> {
9
+ private packageCache;
10
+ private phase;
11
+ private context;
12
+ private kind;
13
+ static create({ packageCache, phase, build, kind, path, importer, pluginData, }: {
14
+ packageCache: PackageCache;
15
+ phase: 'bundling' | 'other';
16
+ build: PluginBuild;
17
+ kind: ImportKind;
18
+ path: string;
19
+ importer: string | undefined;
20
+ pluginData: Record<string, any> | undefined;
21
+ }): {
22
+ initialState: {
23
+ specifier: string;
24
+ fromFile: string;
25
+ meta: any;
26
+ };
27
+ adapter: EsBuildRequestAdapter;
28
+ } | undefined;
29
+ private constructor();
30
+ get debugType(): string;
31
+ notFoundResponse(request: core.ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>): Resolution<OnResolveResult, OnResolveResult>;
32
+ virtualResponse(_request: core.ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>, virtualFileName: string): Resolution<OnResolveResult, OnResolveResult>;
33
+ resolve(request: ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>): Promise<Resolution<OnResolveResult, OnResolveResult>>;
34
+ }
35
+ export declare function writeStatus(id: string, status: InternalStatus): void;
36
+ type InternalStatus = {
37
+ type: 'pending';
38
+ } | {
39
+ type: 'not_found';
40
+ } | {
41
+ type: 'found';
42
+ filename: string;
43
+ };
44
+ export {};
@@ -0,0 +1,158 @@
1
+ import core from '@embroider/core';
2
+ const { cleanUrl, packageName } = core;
3
+ import { dirname } from 'path';
4
+ import { externalName } from '@embroider/reverse-exports';
5
+ export class EsBuildRequestAdapter {
6
+ static create({ packageCache, phase, build, kind, path, importer, pluginData, }) {
7
+ var _a, _b, _c;
8
+ if (!((_b = (_a = pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroider) === null || _a === void 0 ? void 0 : _a.enableCustomResolver) !== null && _b !== void 0 ? _b : true)) {
9
+ return;
10
+ }
11
+ if (path && importer && path[0] !== '\0' && !path.startsWith('virtual-module:')) {
12
+ let fromFile = cleanUrl(importer);
13
+ return {
14
+ initialState: {
15
+ specifier: path,
16
+ fromFile,
17
+ meta: (_c = pluginData === null || pluginData === void 0 ? void 0 : pluginData.embroider) === null || _c === void 0 ? void 0 : _c.meta,
18
+ },
19
+ adapter: new EsBuildRequestAdapter(packageCache, phase, build, kind),
20
+ };
21
+ }
22
+ }
23
+ constructor(packageCache, phase, context, kind) {
24
+ this.packageCache = packageCache;
25
+ this.phase = phase;
26
+ this.context = context;
27
+ this.kind = kind;
28
+ }
29
+ get debugType() {
30
+ return 'esbuild';
31
+ }
32
+ notFoundResponse(request) {
33
+ return {
34
+ type: 'not_found',
35
+ err: {
36
+ errors: [{ text: `module not found ${request.specifier}` }],
37
+ },
38
+ };
39
+ }
40
+ virtualResponse(_request, virtualFileName) {
41
+ return {
42
+ type: 'found',
43
+ filename: virtualFileName,
44
+ result: { path: virtualFileName, namespace: 'embroider-virtual' },
45
+ isVirtual: true,
46
+ };
47
+ }
48
+ async resolve(request) {
49
+ requestStatus(request.specifier);
50
+ let result = await this.context.resolve(request.specifier, {
51
+ importer: request.fromFile,
52
+ resolveDir: dirname(request.fromFile),
53
+ kind: this.kind,
54
+ pluginData: {
55
+ embroider: {
56
+ enableCustomResolver: false,
57
+ meta: request.meta,
58
+ },
59
+ },
60
+ });
61
+ let status = readStatus(request.specifier);
62
+ if (result.errors.length > 0 || status.type === 'not_found') {
63
+ return { type: 'not_found', err: result };
64
+ }
65
+ else {
66
+ if (this.phase === 'bundling') {
67
+ // we need to ensure that we don't traverse back into the app while
68
+ // doing dependency pre-bundling. There are multiple ways an addon can
69
+ // resolve things from the app, due to the existince of both app-js
70
+ // (modules in addons that are logically part of the app's namespace)
71
+ // and non-strict handlebars (which resolves
72
+ // components/helpers/modifiers against the app's global pool).
73
+ let pkg = this.packageCache.ownerOfFile(result.path);
74
+ if ((pkg === null || pkg === void 0 ? void 0 : pkg.root) === this.packageCache.appRoot &&
75
+ // vite provides node built-in polyfills under a custom namespace and we dont
76
+ // want to interrupt that. We'd prefer they get bundled in the dep optimizer normally,
77
+ // rather than getting deferred to the app build (which also works, but means they didn't
78
+ // get pre-optimized).
79
+ (result.namespace === 'file' || result.namespace.startsWith('embroider-'))) {
80
+ let externalizedName = request.specifier;
81
+ if (!packageName(externalizedName)) {
82
+ // the request was a relative path. This won't remain valid once
83
+ // it has been bundled into vite/deps. But we know it targets the
84
+ // app, so we can always convert it into a non-relative import
85
+ // from the app's namespace
86
+ //
87
+ // IMPORTANT: whenever an addon resolves a relative path to the
88
+ // app, it does so because our code in the core resolver has
89
+ // rewritten the request to be relative to the app's root. So here
90
+ // we will only ever encounter relative paths that are already
91
+ // relative to the app's root directory.
92
+ externalizedName = externalName(pkg.packageJSON, externalizedName) || externalizedName;
93
+ }
94
+ return {
95
+ type: 'found',
96
+ filename: externalizedName,
97
+ isVirtual: false,
98
+ result: {
99
+ path: externalizedName,
100
+ external: true,
101
+ },
102
+ };
103
+ }
104
+ }
105
+ let filename;
106
+ if (status.type === 'found' && result.external) {
107
+ // when we know that the file was really found, but vite has
108
+ // externalized it, report the true filename that was found, not the
109
+ // externalized request path.
110
+ filename = status.filename;
111
+ }
112
+ else {
113
+ filename = result.path;
114
+ }
115
+ return {
116
+ type: 'found',
117
+ filename,
118
+ result,
119
+ isVirtual: false,
120
+ };
121
+ }
122
+ }
123
+ }
124
+ /*
125
+ This is an unfortunate necessity. During depscan, vite deliberately hides
126
+ information from esbuild. Specifically, it treats "not found" and "this is an
127
+ external dependency" as both "external: true". But we really care about the
128
+ difference, since we have fallback behaviors for the "not found" case. Using
129
+ this global state, our rollup resolver plugin can observe what vite is
130
+ actually doing and communicate that knowledge outward to our esbuild resolver
131
+ plugin.
132
+ */
133
+ function sharedGlobalState() {
134
+ let channel = globalThis.__embroider_vite_resolver_channel__;
135
+ if (!channel) {
136
+ channel = new Map();
137
+ globalThis.__embroider_vite_resolver_channel__ = channel;
138
+ }
139
+ return channel;
140
+ }
141
+ function requestStatus(id) {
142
+ sharedGlobalState().set(id, { type: 'pending' });
143
+ }
144
+ export function writeStatus(id, status) {
145
+ var _a;
146
+ let channel = sharedGlobalState();
147
+ if (((_a = channel.get(id)) === null || _a === void 0 ? void 0 : _a.type) === 'pending') {
148
+ channel.set(id, status);
149
+ }
150
+ }
151
+ function readStatus(id) {
152
+ var _a;
153
+ let channel = sharedGlobalState();
154
+ let result = (_a = channel.get(id)) !== null && _a !== void 0 ? _a : { type: 'pending' };
155
+ channel.delete(id);
156
+ return result;
157
+ }
158
+ //# sourceMappingURL=esbuild-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild-request.js","sourceRoot":"","sources":["esbuild-request.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAK1D,MAAM,OAAO,qBAAqB;IAChC,MAAM,CAAC,MAAM,CAAC,EACZ,YAAY,EACZ,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,GASX;;QACC,IAAI,CAAC,CAAC,MAAA,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,0CAAE,oBAAoB,mCAAI,IAAI,CAAC,EAAE,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAChF,IAAI,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO;gBACL,YAAY,EAAE;oBACZ,SAAS,EAAE,IAAI;oBACf,QAAQ;oBACR,IAAI,EAAE,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,0CAAE,IAAI;iBAClC;gBACD,OAAO,EAAE,IAAI,qBAAqB,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC;aACrE,CAAC;QACJ,CAAC;IACH,CAAC;IAED,YACU,YAA0B,EAC1B,KAA2B,EAC3B,OAAoB,EACpB,IAAgB;QAHhB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,UAAK,GAAL,KAAK,C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C","sourcesContent":["import core from '@embroider/core';\nconst { cleanUrl, packageName } = core;\nimport type { ImportKind, OnResolveResult, PluginBuild } from 'esbuild';\nimport { dirname } from 'path';\n\nimport type { PackageCache as _PackageCache, Resolution, ModuleRequest, RequestAdapter } from '@embroider/core';\nimport { externalName } from '@embroider/reverse-exports';\n\ntype PublicAPI<T> = { [K in keyof T]: T[K] };\ntype PackageCache = PublicAPI<_PackageCache>;\n\nexport class EsBuildRequestAdapter implements RequestAdapter<Resolution<OnResolveResult, OnResolveResult>> {\n static create({\n packageCache,\n phase,\n build,\n kind,\n path,\n importer,\n pluginData,\n }: {\n packageCache: PackageCache;\n phase: 'bundling' | 'other';\n build: PluginBuild;\n kind: ImportKind;\n path: string;\n importer: string | undefined;\n pluginData: Record<string, any> | undefined;\n }) {\n if (!(pluginData?.embroider?.enableCustomResolver ?? true)) {\n return;\n }\n\n if (path && importer && path[0] !== '\\0' && !path.startsWith('virtual-module:')) {\n let fromFile = cleanUrl(importer);\n return {\n initialState: {\n specifier: path,\n fromFile,\n meta: pluginData?.embroider?.meta,\n },\n adapter: new EsBuildRequestAdapter(packageCache, phase, build, kind),\n };\n }\n }\n\n private constructor(\n private packageCache: PackageCache,\n private phase: 'bundling' | 'other',\n private context: PluginBuild,\n private kind: ImportKind\n ) {}\n\n get debugType() {\n return 'esbuild';\n }\n\n notFoundResponse(\n request: core.ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>\n ): Resolution<OnResolveResult, OnResolveResult> {\n return {\n type: 'not_found',\n err: {\n errors: [{ text: `module not found ${request.specifier}` }],\n },\n };\n }\n\n virtualResponse(\n _request: core.ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>,\n virtualFileName: string\n ): Resolution<OnResolveResult, OnResolveResult> {\n return {\n type: 'found',\n filename: virtualFileName,\n result: { path: virtualFileName, namespace: 'embroider-virtual' },\n isVirtual: true,\n };\n }\n\n async resolve(\n request: ModuleRequest<Resolution<OnResolveResult, OnResolveResult>>\n ): Promise<Resolution<OnResolveResult, OnResolveResult>> {\n requestStatus(request.specifier);\n\n let result = await this.context.resolve(request.specifier, {\n importer: request.fromFile,\n resolveDir: dirname(request.fromFile),\n kind: this.kind,\n pluginData: {\n embroider: {\n enableCustomResolver: false,\n meta: request.meta,\n },\n },\n });\n\n let status = readStatus(request.specifier);\n\n if (result.errors.length > 0 || status.type === 'not_found') {\n return { type: 'not_found', err: result };\n } else {\n if (this.phase === 'bundling') {\n // we need to ensure that we don't traverse back into the app while\n // doing dependency pre-bundling. There are multiple ways an addon can\n // resolve things from the app, due to the existince of both app-js\n // (modules in addons that are logically part of the app's namespace)\n // and non-strict handlebars (which resolves\n // components/helpers/modifiers against the app's global pool).\n let pkg = this.packageCache.ownerOfFile(result.path);\n if (\n pkg?.root === this.packageCache.appRoot &&\n // vite provides node built-in polyfills under a custom namespace and we dont\n // want to interrupt that. We'd prefer they get bundled in the dep optimizer normally,\n // rather than getting deferred to the app build (which also works, but means they didn't\n // get pre-optimized).\n (result.namespace === 'file' || result.namespace.startsWith('embroider-'))\n ) {\n let externalizedName = request.specifier;\n if (!packageName(externalizedName)) {\n // the request was a relative path. This won't remain valid once\n // it has been bundled into vite/deps. But we know it targets the\n // app, so we can always convert it into a non-relative import\n // from the app's namespace\n //\n // IMPORTANT: whenever an addon resolves a relative path to the\n // app, it does so because our code in the core resolver has\n // rewritten the request to be relative to the app's root. So here\n // we will only ever encounter relative paths that are already\n // relative to the app's root directory.\n externalizedName = externalName(pkg.packageJSON, externalizedName) || externalizedName;\n }\n return {\n type: 'found',\n filename: externalizedName,\n isVirtual: false,\n result: {\n path: externalizedName,\n external: true,\n },\n };\n }\n }\n\n let filename: string;\n if (status.type === 'found' && result.external) {\n // when we know that the file was really found, but vite has\n // externalized it, report the true filename that was found, not the\n // externalized request path.\n filename = status.filename;\n } else {\n filename = result.path;\n }\n\n return {\n type: 'found',\n filename,\n result,\n isVirtual: false,\n };\n }\n }\n}\n\n/*\n This is an unfortunate necessity. During depscan, vite deliberately hides\n information from esbuild. Specifically, it treats \"not found\" and \"this is an\n external dependency\" as both \"external: true\". But we really care about the\n difference, since we have fallback behaviors for the \"not found\" case. Using\n this global state, our rollup resolver plugin can observe what vite is\n actually doing and communicate that knowledge outward to our esbuild resolver\n plugin.\n */\nfunction sharedGlobalState() {\n let channel = (globalThis as any).__embroider_vite_resolver_channel__ as undefined | Map<string, InternalStatus>;\n if (!channel) {\n channel = new Map();\n (globalThis as any).__embroider_vite_resolver_channel__ = channel;\n }\n return channel;\n}\n\nfunction requestStatus(id: string): void {\n sharedGlobalState().set(id, { type: 'pending' });\n}\n\nexport function writeStatus(id: string, status: InternalStatus): void {\n let channel = sharedGlobalState();\n if (channel.get(id)?.type === 'pending') {\n channel.set(id, status);\n }\n}\n\nfunction readStatus(id: string): InternalStatus {\n let channel = sharedGlobalState();\n let result = channel.get(id) ?? { type: 'pending' };\n channel.delete(id);\n return result;\n}\n\ntype InternalStatus = { type: 'pending' } | { type: 'not_found' } | { type: 'found'; filename: string };\n"]}