@embroider/addon-dev 8.4.1 → 8.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.
Files changed (38) hide show
  1. package/README.md +2 -2
  2. package/package.json +4 -2
  3. package/src/commands.d.ts +3 -0
  4. package/src/commands.js +70 -0
  5. package/src/commands.js.map +1 -0
  6. package/src/rollup-addon-dependencies.d.ts +3 -0
  7. package/src/rollup-addon-dependencies.js +46 -0
  8. package/src/rollup-addon-dependencies.js.map +1 -0
  9. package/src/rollup-app-reexports.d.ts +10 -0
  10. package/src/rollup-app-reexports.js +51 -0
  11. package/src/rollup-app-reexports.js.map +1 -0
  12. package/src/rollup-declarations.d.ts +10 -0
  13. package/src/rollup-declarations.js +134 -0
  14. package/src/rollup-declarations.js.map +1 -0
  15. package/src/rollup-gjs-plugin.d.ts +3 -0
  16. package/src/rollup-gjs-plugin.js +36 -0
  17. package/src/rollup-gjs-plugin.js.map +1 -0
  18. package/src/rollup-hbs-plugin.d.ts +5 -0
  19. package/src/rollup-hbs-plugin.js +105 -0
  20. package/src/rollup-hbs-plugin.js.map +1 -0
  21. package/src/rollup-incremental-plugin.d.ts +3 -0
  22. package/src/rollup-incremental-plugin.js +76 -0
  23. package/src/rollup-incremental-plugin.js.map +1 -0
  24. package/src/rollup-keep-assets.d.ts +7 -0
  25. package/src/rollup-keep-assets.js +123 -0
  26. package/src/rollup-keep-assets.js.map +1 -0
  27. package/src/rollup-public-assets.d.ts +23 -0
  28. package/src/rollup-public-assets.js +51 -0
  29. package/src/rollup-public-assets.js.map +1 -0
  30. package/src/rollup-public-entrypoints.d.ts +7 -0
  31. package/src/rollup-public-entrypoints.js +83 -0
  32. package/src/rollup-public-entrypoints.js.map +1 -0
  33. package/src/rollup.d.ts +33 -0
  34. package/src/rollup.js +116 -0
  35. package/src/rollup.js.map +1 -0
  36. package/src/template-colocation-plugin.d.ts +4 -0
  37. package/src/template-colocation-plugin.js +5 -0
  38. package/src/template-colocation-plugin.js.map +1 -0
package/README.md CHANGED
@@ -19,7 +19,7 @@ For a guide on porting a V1 addon to V2, see https://github.com/embroider-build/
19
19
 
20
20
  ### addon.publicAssets(path <required>, options)
21
21
 
22
- A rollup plugin to expose a folder of assets. `path` is a required to define which folder to expose. `options.include` is a glob pattern passed to `walkSync.include` to pick files. `options.exlude` is a glob pattern passed to `walkSync.ignore` to exclude files. `options.namespace` is the namespace to expose files, defaults to the package name + the path that you provided e.g. if you call `addon.publicAssets('public')` in a v2 addon named `super-addon` then your namespace will default to `super-addon/public`.
22
+ A rollup plugin to expose a folder of assets. `path` is required to define which folder to expose. `options.include` is a glob pattern passed to `walkSync.include` to pick files. `options.exclude` is a glob pattern passed to `walkSync.ignore` to exclude files. `options.namespace` is the namespace to expose files, defaults to the package name + the path that you provided e.g. if you call `addon.publicAssets('public')` in a v2 addon named `super-addon` then your namespace will default to `super-addon/public`.
23
23
 
24
24
  ### addon.keepAssets(patterns: string[], exports?: 'default' | '*')
25
25
 
@@ -39,7 +39,7 @@ The `exports` option defaults to `undefined` which means the assets are used for
39
39
  addon.keepAssets(["**/*.png"], "default")
40
40
  ```
41
41
 
42
- lets you say `import imageURL from './my-image.png'`. Not that this pattern is **not** automatically supported in V2 addons and you would need to tell apps that consume your addon to handle it in a custom way.
42
+ lets you say `import imageURL from './my-image.png'`. Note that this pattern is **not** automatically supported in V2 addons and you would need to tell apps that consume your addon to handle it in a custom way.
43
43
 
44
44
  ## addon-dev command
45
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/addon-dev",
3
- "version": "8.4.1",
3
+ "version": "8.5.0",
4
4
  "description": "Utilities for addon authors",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,12 +34,13 @@
34
34
  "content-tag": "^4.1.0",
35
35
  "execa": "^5.1.1",
36
36
  "fs-extra": "^10.0.0",
37
+ "magic-string": "^0.30.2",
37
38
  "minimatch": "^3.0.4",
38
39
  "package-up": "^5.0.0",
39
40
  "rollup-plugin-copy-assets": "^2.0.3",
40
41
  "walk-sync": "^3.0.0",
41
42
  "yargs": "^17.0.1",
42
- "@embroider/core": "^4.6.8"
43
+ "@embroider/core": "^4.6.10"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@glimmer/syntax": "^0.94.9",
@@ -49,6 +50,7 @@
49
50
  "@glint/environment-ember-loose": "^1.5.0",
50
51
  "@glint/environment-ember-template-imports": "^1.5.0",
51
52
  "@glint/template": "^1.5.0",
53
+ "@jridgewell/trace-mapping": "^0.3.25",
52
54
  "@types/fs-extra": "^9.0.12",
53
55
  "@types/minimatch": "^3.0.4",
54
56
  "@types/yargs": "^17.0.3",
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_extra_1 = require("fs-extra");
8
+ const path_1 = require("path");
9
+ const yargs_1 = __importDefault(require("yargs/yargs"));
10
+ function commonArgs(yargs) {
11
+ return yargs
12
+ .option('testAppDir', {
13
+ type: 'string',
14
+ description: 'Path to the test app',
15
+ default: 'test-app',
16
+ })
17
+ .option('addonDir', {
18
+ type: 'string',
19
+ description: 'Path to your addon',
20
+ default: process.cwd(),
21
+ });
22
+ }
23
+ (0, yargs_1.default)(process.argv.slice(2))
24
+ .scriptName('addon-dev')
25
+ .command('link-test-app', 'Ensures that a test app (that lives a subdir under an addon) has access to the addon and all appropriate deps', (yargs) => commonArgs(yargs), function (opts) {
26
+ let { testAppDir, addonDir } = opts;
27
+ (0, fs_extra_1.ensureSymlinkSync)((0, path_1.join)(addonDir, 'node_modules', '.bin'), (0, path_1.join)(testAppDir, 'node_modules', '.bin'), 'dir');
28
+ (0, fs_extra_1.ensureSymlinkSync)(addonDir, (0, path_1.join)(testAppDir, 'node_modules', (0, fs_extra_1.readJSONSync)((0, path_1.join)(addonDir, 'package.json')).name));
29
+ })
30
+ .command('sync-dev-deps', `Synchronizes a test app's devDependencies into the parent addon's devDependencies`, (yargs) => {
31
+ return commonArgs(yargs).option('lint', {
32
+ type: 'boolean',
33
+ description: 'Instead of modifying package.json, print what would have been modified and exit with a failure if any changes are required.',
34
+ default: false,
35
+ });
36
+ }, function (opts) {
37
+ let { testAppDir, addonDir, lint } = opts;
38
+ let addonPkg = (0, fs_extra_1.readJSONSync)((0, path_1.join)(addonDir, 'package.json'));
39
+ let testPkg = (0, fs_extra_1.readJSONSync)((0, path_1.join)(testAppDir, 'package.json'));
40
+ let foundDifferences = false;
41
+ let devDeps = Object.assign({}, addonPkg.devDependencies);
42
+ for (let [name, range] of Object.entries(testPkg.devDependencies)) {
43
+ if (name === addonPkg.name) {
44
+ continue;
45
+ }
46
+ if (devDeps[name] !== range) {
47
+ foundDifferences = true;
48
+ if (lint) {
49
+ console.error(`test app depends on ${name} ${range} but that is not present in addon's devDependencies package.json`);
50
+ }
51
+ else {
52
+ devDeps[name] = range;
53
+ }
54
+ }
55
+ }
56
+ if (!foundDifferences) {
57
+ return;
58
+ }
59
+ if (lint) {
60
+ process.exit(-1);
61
+ }
62
+ else {
63
+ addonPkg.devDependencies = devDeps;
64
+ (0, fs_extra_1.writeJSONSync)((0, path_1.join)(addonDir, 'package.json'), addonPkg, { spaces: 2 });
65
+ }
66
+ })
67
+ .demandCommand()
68
+ .strictCommands()
69
+ .help().argv;
70
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["commands.ts"],"names":[],"mappings":";;;;;;AAEA,uCAA0E;AAC1E,+BAA4B;AAC5B,wDAAgC;AAGhC,SAAS,UAAU,CAAC,KAAW;IAC7B,OAAO,KAAK;SACT,MAAM,CAAC,YAAY,EAAE;QACpB,IAAI,EAAE,QAAQ;Q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port { ensureSymlinkSync, readJSONSync, writeJSONSync } from 'fs-extra';\nimport { join } from 'path';\nimport yargs from 'yargs/yargs';\nimport type { Argv } from 'yargs';\n\nfunction commonArgs(yargs: Argv) {\n return yargs\n .option('testAppDir', {\n type: 'string',\n description: 'Path to the test app',\n default: 'test-app',\n })\n .option('addonDir', {\n type: 'string',\n description: 'Path to your addon',\n default: process.cwd(),\n });\n}\n\nyargs(process.argv.slice(2))\n .scriptName('addon-dev')\n .command(\n 'link-test-app',\n 'Ensures that a test app (that lives a subdir under an addon) has access to the addon and all appropriate deps',\n (yargs) => commonArgs(yargs),\n function (opts) {\n let { testAppDir, addonDir } = opts;\n ensureSymlinkSync(\n join(addonDir, 'node_modules', '.bin'),\n join(testAppDir, 'node_modules', '.bin'),\n 'dir'\n );\n ensureSymlinkSync(\n addonDir,\n join(\n testAppDir,\n 'node_modules',\n readJSONSync(join(addonDir, 'package.json')).name\n )\n );\n }\n )\n .command(\n 'sync-dev-deps',\n `Synchronizes a test app's devDependencies into the parent addon's devDependencies`,\n (yargs) => {\n return commonArgs(yargs).option('lint', {\n type: 'boolean',\n description:\n 'Instead of modifying package.json, print what would have been modified and exit with a failure if any changes are required.',\n default: false,\n });\n },\n function (opts) {\n let { testAppDir, addonDir, lint } = opts;\n let addonPkg = readJSONSync(join(addonDir, 'package.json'));\n let testPkg = readJSONSync(join(testAppDir, 'package.json'));\n let foundDifferences = false;\n let devDeps: { [name: string]: string } = Object.assign(\n {},\n addonPkg.devDependencies\n );\n for (let [name, range] of Object.entries(\n testPkg.devDependencies as { [name: string]: string }\n )) {\n if (name === addonPkg.name) {\n continue;\n }\n if (devDeps[name] !== range) {\n foundDifferences = true;\n if (lint) {\n console.error(\n `test app depends on ${name} ${range} but that is not present in addon's devDependencies package.json`\n );\n } else {\n devDeps[name] = range;\n }\n }\n }\n if (!foundDifferences) {\n return;\n }\n if (lint) {\n process.exit(-1);\n } else {\n addonPkg.devDependencies = devDeps;\n writeJSONSync(join(addonDir, 'package.json'), addonPkg, { spaces: 2 });\n }\n }\n )\n .demandCommand()\n .strictCommands()\n .help().argv;\n"]}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'rollup';
2
+ export default function emberExternals(): Plugin;
3
+ //# sourceMappingURL=rollup-addon-dependencies.d.ts.map
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = emberExternals;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const core_1 = require("@embroider/core");
6
+ const compilationModules = new Set(core_1.templateCompilationModules.map((m) => m.module));
7
+ function resolvableDependencies() {
8
+ let deps = new Set();
9
+ let pkg = (0, fs_extra_1.readJsonSync)('package.json');
10
+ if (pkg.dependencies) {
11
+ for (let name of Object.keys(pkg.dependencies)) {
12
+ deps.add(name);
13
+ }
14
+ }
15
+ if (pkg.peerDependencies) {
16
+ for (let name of Object.keys(pkg.peerDependencies)) {
17
+ deps.add(name);
18
+ }
19
+ }
20
+ return deps;
21
+ }
22
+ function emberExternals() {
23
+ let deps;
24
+ return {
25
+ name: 'ember-externals',
26
+ buildStart() {
27
+ this.addWatchFile('package.json');
28
+ deps = resolvableDependencies();
29
+ },
30
+ async resolveId(source) {
31
+ let pkgName = (0, core_1.packageName)(source);
32
+ if (!pkgName) {
33
+ // No package name found means this is a relative import, which we don't
34
+ // need to deal with.
35
+ return;
36
+ }
37
+ if (deps.has(pkgName) ||
38
+ core_1.emberVirtualPeerDeps.has(pkgName) ||
39
+ core_1.emberVirtualPackages.has(pkgName) ||
40
+ compilationModules.has(pkgName)) {
41
+ return { id: source, external: true };
42
+ }
43
+ },
44
+ };
45
+ }
46
+ //# sourceMappingURL=rollup-addon-dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup-addon-dependencies.js","sourceRoot":"","sources":["rollup-addon-dependencies.ts"],"names":[],"mappings":";;AA6BA,iCA6BC;AAzDD,uCAAwC;AACxC,0CAKyB;AAEzB,MAAM,kBAAkB,GAA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G,CAAC,OAAO,CAAC,EAC/B,CAAC;gBACD,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YACxC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from 'rollup';\nimport { readJsonSync } from 'fs-extra';\nimport {\n emberVirtualPackages,\n emberVirtualPeerDeps,\n packageName,\n templateCompilationModules,\n} from '@embroider/core';\n\nconst compilationModules = new Set(\n templateCompilationModules.map((m) => m.module)\n);\n\nfunction resolvableDependencies(): Set<string> {\n let deps = new Set<string>();\n let pkg = readJsonSync('package.json');\n if (pkg.dependencies) {\n for (let name of Object.keys(pkg.dependencies)) {\n deps.add(name);\n }\n }\n if (pkg.peerDependencies) {\n for (let name of Object.keys(pkg.peerDependencies)) {\n deps.add(name);\n }\n }\n return deps;\n}\n\nexport default function emberExternals(): Plugin {\n let deps: Set<string>;\n\n return {\n name: 'ember-externals',\n\n buildStart() {\n this.addWatchFile('package.json');\n deps = resolvableDependencies();\n },\n\n async resolveId(source) {\n let pkgName = packageName(source);\n if (!pkgName) {\n // No package name found means this is a relative import, which we don't\n // need to deal with.\n return;\n }\n\n if (\n deps.has(pkgName) ||\n emberVirtualPeerDeps.has(pkgName) ||\n emberVirtualPackages.has(pkgName) ||\n compilationModules.has(pkgName)\n ) {\n return { id: source, external: true };\n }\n },\n };\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'rollup';
2
+ export default function appReexports(opts: {
3
+ from: string;
4
+ to: string;
5
+ include: string[];
6
+ exclude?: string[];
7
+ mapFilename?: (filename: string) => string;
8
+ exports?: (filename: string) => string[] | string | undefined;
9
+ }): Plugin;
10
+ //# sourceMappingURL=rollup-app-reexports.d.ts.map
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = appReexports;
7
+ const fs_extra_1 = require("fs-extra");
8
+ const path_1 = require("path");
9
+ const minimatch_1 = __importDefault(require("minimatch"));
10
+ function symmetricDifference(arr1, arr2) {
11
+ return arr1
12
+ .filter((x) => !arr2.includes(x))
13
+ .concat(arr2.filter((x) => !arr1.includes(x)));
14
+ }
15
+ function appReexports(opts) {
16
+ return {
17
+ name: 'app-reexports',
18
+ generateBundle(_, bundle) {
19
+ var _a, _b, _c, _d, _e, _f;
20
+ let pkg = (0, fs_extra_1.readJsonSync)('package.json');
21
+ let appJS = {};
22
+ for (let addonFilename of Object.keys(bundle)) {
23
+ let appFilename = (_b = (_a = opts.mapFilename) === null || _a === void 0 ? void 0 : _a.call(opts, addonFilename)) !== null && _b !== void 0 ? _b : addonFilename;
24
+ let appExports = ((_c = opts.exports) === null || _c === void 0 ? void 0 : _c.call(opts, addonFilename)) || ['default'];
25
+ let computedExports = typeof appExports === 'string'
26
+ ? appExports
27
+ : `{ ${appExports.join(', ')} }`;
28
+ if (opts.include.some((glob) => (0, minimatch_1.default)(addonFilename, glob)) &&
29
+ !(0, minimatch_1.default)(addonFilename, '**/*.d.ts') &&
30
+ ((_d = opts.exclude) === null || _d === void 0 ? void 0 : _d.some((glob) => (0, minimatch_1.default)(addonFilename, glob))) !== true) {
31
+ appJS[`./${appFilename}`] = `./dist/_app_/${appFilename}`;
32
+ this.emitFile({
33
+ type: 'asset',
34
+ fileName: `_app_/${appFilename}`,
35
+ source: `export ${computedExports} from "${pkg.name}/${addonFilename.slice(0, -(0, path_1.extname)(addonFilename).length)}";\n`,
36
+ });
37
+ }
38
+ }
39
+ let originalAppJS = (_f = (_e = pkg['ember-addon']) === null || _e === void 0 ? void 0 : _e['app-js']) !== null && _f !== void 0 ? _f : {};
40
+ let hasChanges = !!symmetricDifference(Object.keys(originalAppJS), Object.keys(appJS)).length;
41
+ // Don't cause a file i/o event unless something actually changed
42
+ if (hasChanges) {
43
+ pkg['ember-addon'] = Object.assign({}, pkg['ember-addon'], {
44
+ 'app-js': appJS,
45
+ });
46
+ (0, fs_extra_1.writeJsonSync)('package.json', pkg, { spaces: 2 });
47
+ }
48
+ },
49
+ };
50
+ }
51
+ //# sourceMappingURL=rollup-app-reexports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup-app-reexports.js","sourceRoot":"","sources":["rollup-app-reexports.ts"],"names":[],"mappings":";;;;;AAWA,+BAqDC;AAhED,uCAAuD;AACvD,+BAA+B;AAC/B,0DAAkC;AAGlC,SAAS,mBAAmB,CAAC,IAAW,EAAE,IAAW;IACnD,OAAO,IAAI;SACR,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SAChC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,SAAwB,YAAY,CAAC,IAOpC;IACC,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,cAAc,CAAC,CAAC,EAAE,MAAM;;YACtB,IAAI,GAAG,GAAG,IAAA,uBAAY,EAAC,cAAc,CAAC,CAAC;YACvC,IAAI,KAAK,GAA2B,EAAE,CAAC;YACvC,KAAK,IAAI,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC9C,IAAI,WAAW,GAAG,MAAA,MAAA,IAAI,CAAC,WAAW,qDAAG,aAAa,CAAC,mCAAI,aAAa,CAAC;gBACrE,IAAI,UAAU,GAAG,CAAA,MAAA,IAAI,CAAC,OAAO,qDAAG,aAAa,CAAC,KAAI,CAAC,SAAS,CAAC,CAAC;gBAE9D,IAAI,eAAe,GACjB,OAAO,UAAU,KAAK,QAAQ;oBAC5B,CAAC,CAAC,UAAU;oBACZ,CAAC,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,IAAI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AE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { readJsonSync, writeJsonSync } from 'fs-extra';\nimport { extname } from 'path';\nimport minimatch from 'minimatch';\nimport type { Plugin } from 'rollup';\n\nfunction symmetricDifference(arr1: any[], arr2: any[]) {\n return arr1\n .filter((x) => !arr2.includes(x))\n .concat(arr2.filter((x) => !arr1.includes(x)));\n}\n\nexport default function appReexports(opts: {\n from: string;\n to: string;\n include: string[];\n exclude?: string[];\n mapFilename?: (filename: string) => string;\n exports?: (filename: string) => string[] | string | undefined;\n}): Plugin {\n return {\n name: 'app-reexports',\n generateBundle(_, bundle) {\n let pkg = readJsonSync('package.json');\n let appJS: Record<string, string> = {};\n for (let addonFilename of Object.keys(bundle)) {\n let appFilename = opts.mapFilename?.(addonFilename) ?? addonFilename;\n let appExports = opts.exports?.(addonFilename) || ['default'];\n\n let computedExports =\n typeof appExports === 'string'\n ? appExports\n : `{ ${appExports.join(', ')} }`;\n\n if (\n opts.include.some((glob) => minimatch(addonFilename, glob)) &&\n !minimatch(addonFilename, '**/*.d.ts') &&\n opts.exclude?.some((glob) => minimatch(addonFilename, glob)) !== true\n ) {\n appJS[`./${appFilename}`] = `./dist/_app_/${appFilename}`;\n this.emitFile({\n type: 'asset',\n fileName: `_app_/${appFilename}`,\n source: `export ${computedExports} from \"${\n pkg.name\n }/${addonFilename.slice(0, -extname(addonFilename).length)}\";\\n`,\n });\n }\n }\n let originalAppJS = pkg['ember-addon']?.['app-js'] ?? {};\n\n let hasChanges = !!symmetricDifference(\n Object.keys(originalAppJS),\n Object.keys(appJS)\n ).length;\n\n // Don't cause a file i/o event unless something actually changed\n if (hasChanges) {\n pkg['ember-addon'] = Object.assign({}, pkg['ember-addon'], {\n 'app-js': appJS,\n });\n writeJsonSync('package.json', pkg, { spaces: 2 });\n }\n },\n };\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'rollup';
2
+ export default function rollupDeclarationsPlugin(declarationsDir: string,
3
+ /**
4
+ * The command to use to generate types.
5
+ * Defaults to:
6
+ * - glint --declaration # for glint v1
7
+ * - ember-tsc --declaration # for glint v2
8
+ */
9
+ command?: string): Plugin;
10
+ //# sourceMappingURL=rollup-declarations.d.ts.map
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = rollupDeclarationsPlugin;
7
+ const execa_1 = __importDefault(require("execa"));
8
+ const walk_sync_1 = __importDefault(require("walk-sync"));
9
+ const promises_1 = require("fs/promises");
10
+ const fs_1 = require("fs");
11
+ const package_up_1 = require("package-up");
12
+ let glint1 = 'glint --declaration';
13
+ let glint2 = 'ember-tsc --declaration';
14
+ function rollupDeclarationsPlugin(declarationsDir,
15
+ /**
16
+ * The command to use to generate types.
17
+ * Defaults to:
18
+ * - glint --declaration # for glint v1
19
+ * - ember-tsc --declaration # for glint v2
20
+ */
21
+ command) {
22
+ let glintPromise;
23
+ let commandToRun = command;
24
+ async function determineCommand() {
25
+ if (commandToRun)
26
+ return;
27
+ let manifestPath = await (0, package_up_1.packageUp)();
28
+ if (!manifestPath) {
29
+ /**
30
+ * Historical default is to use glint v1
31
+ */
32
+ commandToRun = glint1;
33
+ return;
34
+ }
35
+ let manifestBuffer = (0, fs_1.readFileSync)(manifestPath);
36
+ let manifest = JSON.parse(manifestBuffer.toString());
37
+ let deps = {
38
+ ...manifest.devDependencies,
39
+ ...manifest.dependencies,
40
+ };
41
+ if (deps['@glint/ember-tsc']) {
42
+ commandToRun = glint2;
43
+ return;
44
+ }
45
+ if (deps['@glint/core']) {
46
+ commandToRun = glint1;
47
+ return;
48
+ }
49
+ throw new Error(`Cannot use addon.declarations() plugin without glint present or an explicit command set as the second parameter. e.g.: addon.declarations('declarations', 'tsc --declaration')`);
50
+ }
51
+ return {
52
+ name: 'declarations',
53
+ buildStart() {
54
+ const runGlint = async () => {
55
+ await determineCommand();
56
+ if (!commandToRun)
57
+ return;
58
+ let { exitCode, escapedCommand } = await execa_1.default.command(commandToRun, {
59
+ // using stdio: inherit is the only way to retain color output from the
60
+ // underlying tsc process.
61
+ // However, the viewer of the error will not know which plugin it comes from.
62
+ // So that's why we have the additional logging below
63
+ stdio: 'inherit',
64
+ preferLocal: true,
65
+ // Without reject, execa would throw a hard exception
66
+ reject: false,
67
+ });
68
+ if (exitCode > 0) {
69
+ let msg = `Failed to generate declarations via \`${escapedCommand}\``;
70
+ if (this.meta.watchMode) {
71
+ this.warn(msg);
72
+ }
73
+ else {
74
+ this.error(msg);
75
+ }
76
+ }
77
+ await fixDeclarationsInMatchingFiles(declarationsDir);
78
+ if (exitCode === 0) {
79
+ this.info(`\`${escapedCommand}\` succeeded`);
80
+ }
81
+ };
82
+ // We just kick off glint here early in the rollup process, without making rollup wait for this to finish, by not returning the promise
83
+ // The output of this is not relevant to further stages of the rollup build, this is just happening in parallel to other rollup compilation
84
+ glintPromise = runGlint();
85
+ },
86
+ // Make rollup wait for glint to have finished before calling the build job done
87
+ writeBundle: () => glintPromise,
88
+ };
89
+ }
90
+ async function fixDeclarationsInMatchingFiles(dir) {
91
+ // can't fix what doesn't exist
92
+ // (happens when glint errors and doesn't output a ${dir} directory
93
+ if (!(0, fs_1.existsSync)(dir)) {
94
+ return;
95
+ }
96
+ const dtsFiles = (0, walk_sync_1.default)(dir, {
97
+ globs: ['**/*.d.ts', '**/*.d.gts.ts', '**/*.d.gjs.ts'],
98
+ directories: false,
99
+ includeBasePath: true,
100
+ });
101
+ return Promise.all(dtsFiles.map(async (file) => {
102
+ // TypeScript has never supported "compiled to JS" workflows
103
+ // when using external tools.
104
+ //
105
+ // So, the "arbitrary extensions" TS emits, will look like .d.gts.ts
106
+ // or .d.gjs.ts
107
+ //
108
+ // Because TS doesn't understand that external tools emit JS,
109
+ // and thus their declarations must be .d.ts, we have to
110
+ // manually handle this rename ourselves.
111
+ //
112
+ // Upstream: https://github.com/microsoft/TypeScript/issues/64053
113
+ // This'll be a no-op if/when TS fixes this.
114
+ let target = file.replace(/\.d\.(gts|gjs)\.ts$/, '.d.ts');
115
+ if (target !== file) {
116
+ await (0, promises_1.rename)(file, target);
117
+ }
118
+ const content = await (0, promises_1.readFile)(target, { encoding: 'utf8' });
119
+ await (0, promises_1.writeFile)(target, fixDeclarations(content));
120
+ }));
121
+ }
122
+ // Strip any .gts/.gjs extension from imports in d.ts files, as these won't
123
+ // resolve once the declaration files themselves are named *.d.ts.
124
+ // See
125
+ // - https://github.com/typed-ember/glint/issues/628
126
+ // - https://github.com/microsoft/TypeScript/issues/64053
127
+ function fixDeclarations(content) {
128
+ return content
129
+ .replace(/from\s+'([^']+)\.(gts|gjs)'/g, `from '$1'`)
130
+ .replace(/from\s+"([^"]+)\.(gts|gjs)"/g, `from '$1'`)
131
+ .replace(/import\("([^"]+)\.(gts|gjs)"\)/g, `import('$1')`)
132
+ .replace(/import\('([^']+)\.(gts|gjs)'\)/g, `import('$1')`);
133
+ }
134
+ //# sourceMappingURL=rollup-declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup-declarations.js","sourceRoot":"","sources":["rollup-declarations.ts"],"names":[],"mappings":";;;;;AAUA,2CA0FC;AAnGD,kDAA0B;AAC1B,0DAAiC;AACjC,0CAA0D;AAC1D,2BAA8C;AAC9C,2CAAuC;AAEvC,IAAI,MAAM,GAAG,qBAAqB,CAAC;AACnC,IAAI,MAAM,GAAG,yBAAyB,CAAC;AAEvC,SAAwB,wBAAwB,CAC9C,eAAuB;AACvB;;;;;GAKG;AACH,OAAgB;IAEhB,IAAI,YAA2B,CAAC;IAEhC,IAAI,YAAY,GAAG,OAAO,CAAC;IAE3B,KAAK,UAAU,gBAAgB;QAC7B,IAAI,YAAY;YAAE,OAAO;QAEzB,IAAI,YAAY,GAAG,MAAM,IAAA,sBAAS,GAAE,CAAC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AAC;QAC7B,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAE7D,MAAM,IAAA,oBAAS,EAAC,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,kEAAkE;AAClE,MAAM;AACN,qDAAqD;AACrD,0DAA0D;AAC1D,SAAS,eAAe,CAAC,OAAe;IACtC,OAAO,OAAO;SACX,OAAO,CAAC,8BAA8B,EAAE,WAAW,CAAC;SACpD,OAAO,CAAC,8BAA8B,EAAE,WAAW,CAAC;SACpD,OAAO,CAAC,iCAAiC,EAAE,cAAc,CAAC;SAC1D,OAAO,CAAC,iCAAiC,EAAE,cAAc,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import type { Plugin } from 'rollup';\nimport execa from 'execa';\nimport walkSync from 'walk-sync';\nimport { readFile, rename, writeFile } from 'fs/promises';\nimport { existsSync, readFileSync } from 'fs';\nimport { packageUp } from 'package-up';\n\nlet glint1 = 'glint --declaration';\nlet glint2 = 'ember-tsc --declaration';\n\nexport default function rollupDeclarationsPlugin(\n declarationsDir: string,\n /**\n * The command to use to generate types.\n * Defaults to:\n * - glint --declaration # for glint v1\n * - ember-tsc --declaration # for glint v2\n */\n command?: string\n): Plugin {\n let glintPromise: Promise<void>;\n\n let commandToRun = command;\n\n async function determineCommand() {\n if (commandToRun) return;\n\n let manifestPath = await packageUp();\n if (!manifestPath) {\n /**\n * Historical default is to use glint v1\n */\n commandToRun = glint1;\n return;\n }\n\n let manifestBuffer = readFileSync(manifestPath);\n let manifest = JSON.parse(manifestBuffer.toString());\n let deps = {\n ...manifest.devDependencies,\n ...manifest.dependencies,\n };\n\n if (deps['@glint/ember-tsc']) {\n commandToRun = glint2;\n return;\n }\n if (deps['@glint/core']) {\n commandToRun = glint1;\n return;\n }\n\n throw new Error(\n `Cannot use addon.declarations() plugin without glint present or an explicit command set as the second parameter. e.g.: addon.declarations('declarations', 'tsc --declaration')`\n );\n }\n\n return {\n name: 'declarations',\n buildStart() {\n const runGlint = async () => {\n await determineCommand();\n\n if (!commandToRun) return;\n\n let { exitCode, escapedCommand } = await execa.command(commandToRun, {\n // using stdio: inherit is the only way to retain color output from the\n // underlying tsc process.\n // However, the viewer of the error will not know which plugin it comes from.\n // So that's why we have the additional logging below\n stdio: 'inherit',\n preferLocal: true,\n // Without reject, execa would throw a hard exception\n reject: false,\n });\n\n if (exitCode > 0) {\n let msg = `Failed to generate declarations via \\`${escapedCommand}\\``;\n\n if (this.meta.watchMode) {\n this.warn(msg);\n } else {\n this.error(msg);\n }\n }\n\n await fixDeclarationsInMatchingFiles(declarationsDir);\n if (exitCode === 0) {\n this.info(`\\`${escapedCommand}\\` succeeded`);\n }\n };\n\n // We just kick off glint here early in the rollup process, without making rollup wait for this to finish, by not returning the promise\n // The output of this is not relevant to further stages of the rollup build, this is just happening in parallel to other rollup compilation\n glintPromise = runGlint();\n },\n\n // Make rollup wait for glint to have finished before calling the build job done\n writeBundle: () => glintPromise,\n };\n}\n\nasync function fixDeclarationsInMatchingFiles(dir: string) {\n // can't fix what doesn't exist\n // (happens when glint errors and doesn't output a ${dir} directory\n if (!existsSync(dir)) {\n return;\n }\n\n const dtsFiles = walkSync(dir, {\n globs: ['**/*.d.ts', '**/*.d.gts.ts', '**/*.d.gjs.ts'],\n directories: false,\n includeBasePath: true,\n });\n\n return Promise.all(\n dtsFiles.map(async (file) => {\n // TypeScript has never supported \"compiled to JS\" workflows\n // when using external tools.\n //\n // So, the \"arbitrary extensions\" TS emits, will look like .d.gts.ts\n // or .d.gjs.ts\n //\n // Because TS doesn't understand that external tools emit JS,\n // and thus their declarations must be .d.ts, we have to\n // manually handle this rename ourselves.\n //\n // Upstream: https://github.com/microsoft/TypeScript/issues/64053\n // This'll be a no-op if/when TS fixes this.\n let target = file.replace(/\\.d\\.(gts|gjs)\\.ts$/, '.d.ts');\n\n if (target !== file) {\n await rename(file, target);\n }\n\n const content = await readFile(target, { encoding: 'utf8' });\n\n await writeFile(target, fixDeclarations(content));\n })\n );\n}\n\n// Strip any .gts/.gjs extension from imports in d.ts files, as these won't\n// resolve once the declaration files themselves are named *.d.ts.\n// See\n// - https://github.com/typed-ember/glint/issues/628\n// - https://github.com/microsoft/TypeScript/issues/64053\nfunction fixDeclarations(content: string) {\n return content\n .replace(/from\\s+'([^']+)\\.(gts|gjs)'/g, `from '$1'`)\n .replace(/from\\s+\"([^\"]+)\\.(gts|gjs)\"/g, `from '$1'`)\n .replace(/import\\(\"([^\"]+)\\.(gts|gjs)\"\\)/g, `import('$1')`)\n .replace(/import\\('([^']+)\\.(gts|gjs)'\\)/g, `import('$1')`);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'rollup';
2
+ export default function rollupGjsPlugin(): Plugin;
3
+ //# sourceMappingURL=rollup-gjs-plugin.d.ts.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = rollupGjsPlugin;
4
+ const pluginutils_1 = require("@rollup/pluginutils");
5
+ const content_tag_1 = require("content-tag");
6
+ const PLUGIN_NAME = 'rollup-gjs-plugin';
7
+ const processor = new content_tag_1.Preprocessor();
8
+ // import { parse as pathParse } from 'path';
9
+ function rollupGjsPlugin() {
10
+ return {
11
+ name: PLUGIN_NAME,
12
+ transform: {
13
+ // Enforce running the gjs transform before any others like babel that expect valid JS
14
+ order: 'pre',
15
+ handler(input, id) {
16
+ if (!gjsFilter(id)) {
17
+ return null;
18
+ }
19
+ let { code, map } = processor.process(input, {
20
+ filename: id,
21
+ });
22
+ return {
23
+ code,
24
+ map,
25
+ };
26
+ },
27
+ },
28
+ onLog(_level, log) {
29
+ if (log.code === 'EVAL' && gjsFilter(log.id)) {
30
+ return false;
31
+ }
32
+ },
33
+ };
34
+ }
35
+ const gjsFilter = (0, pluginutils_1.createFilter)('**/*.g{j,t}s');
36
+ //# sourceMappingURL=rollup-gjs-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup-gjs-plugin.js","sourceRoot":"","sources":["rollup-gjs-plugin.ts"],"names":[],"mappings":";;AASA,kCA2BC;AApCD,qDAAmD;AAEnD,6CAA2C;AAE3C,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAM,SAAS,GAAG,IAAI,0BAAY,EAAE,CAAC;AACrC,6CAA6C;AAE7C,SAAwB,eAAe;IACrC,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,SAAS,EAAE;YACT,sFAAsF;YACtF,KAAK,EAAE,KAAK;YACZ,OAAO,CAAC,KAAa,EAAE,EAAU;gBAC/B,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;oBACnB,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE;oBAC3C,QAAQ,EAAE,EAAE;iBACb,CAAC,CAAC;gBACH,OAAO;oBACL,IAAI;oBACJ,GAAG;iBACJ,CAAC;YACJ,CAAC;SACF;QAED,KAAK,CAAC,MAAgB,EAAE,GAAc;YACpC,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC7C,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,cAAc,CAAC,CAAC","sourcesContent":["import { createFilter } from '@rollup/pluginutils';\nimport type { LogLevel, Plugin, RollupLog } from 'rollup';\nimport { Preprocessor } from 'content-tag';\n\nconst PLUGIN_NAME = 'rollup-gjs-plugin';\n\nconst processor = new Preprocessor();\n// import { parse as pathParse } from 'path';\n\nexport default function rollupGjsPlugin(): Plugin {\n return {\n name: PLUGIN_NAME,\n\n transform: {\n // Enforce running the gjs transform before any others like babel that expect valid JS\n order: 'pre',\n handler(input: string, id: string) {\n if (!gjsFilter(id)) {\n return null;\n }\n let { code, map } = processor.process(input, {\n filename: id,\n });\n return {\n code,\n map,\n };\n },\n },\n\n onLog(_level: LogLevel, log: RollupLog): boolean | void {\n if (log.code === 'EVAL' && gjsFilter(log.id)) {\n return false;\n }\n },\n };\n}\n\nconst gjsFilter = createFilter('**/*.g{j,t}s');\n"]}
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from 'rollup';
2
+ export default function rollupHbsPlugin({ excludeColocation, }: {
3
+ excludeColocation?: string[];
4
+ }): Plugin;
5
+ //# sourceMappingURL=rollup-hbs-plugin.d.ts.map
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = rollupHbsPlugin;
7
+ const pluginutils_1 = require("@rollup/pluginutils");
8
+ const minimatch_1 = __importDefault(require("minimatch"));
9
+ const core_1 = require("@embroider/core");
10
+ const path_1 = require("path");
11
+ const hbsFilter = (0, pluginutils_1.createFilter)('**/*.hbs?([?]*)');
12
+ function rollupHbsPlugin({ excludeColocation, }) {
13
+ return {
14
+ name: 'rollup-hbs-plugin',
15
+ async resolveId(source, importer, options) {
16
+ var _a, _b;
17
+ if ((_b = (_a = options.custom) === null || _a === void 0 ? void 0 : _a.embroider) === null || _b === void 0 ? void 0 : _b.isExtensionSearch) {
18
+ return null;
19
+ }
20
+ let resolution = await this.resolve(source, importer, {
21
+ ...options,
22
+ skipSelf: true,
23
+ });
24
+ if (!resolution && (0, path_1.extname)(source) === '') {
25
+ resolution = await this.resolve(source + '.hbs', importer, {
26
+ ...options,
27
+ skipSelf: true,
28
+ });
29
+ }
30
+ if (!resolution) {
31
+ let hbsSource = (0, core_1.syntheticJStoHBS)(source);
32
+ if (hbsSource) {
33
+ resolution = await this.resolve(hbsSource, importer, {
34
+ ...options,
35
+ skipSelf: true,
36
+ custom: {
37
+ embroider: {
38
+ isExtensionSearch: true,
39
+ },
40
+ },
41
+ });
42
+ }
43
+ if (!resolution) {
44
+ return null;
45
+ }
46
+ }
47
+ if (resolution && resolution.id.endsWith('.hbs')) {
48
+ let isExcluded = excludeColocation === null || excludeColocation === void 0 ? void 0 : excludeColocation.some((glob) => (0, minimatch_1.default)(resolution.id, glob));
49
+ if (isExcluded) {
50
+ return resolution;
51
+ }
52
+ }
53
+ let syntheticId = (0, core_1.needsSyntheticComponentJS)(source, resolution.id);
54
+ if (syntheticId) {
55
+ this.addWatchFile(source);
56
+ return {
57
+ id: syntheticId,
58
+ meta: {
59
+ 'rollup-hbs-plugin': {
60
+ type: 'template-only-component-js',
61
+ },
62
+ },
63
+ };
64
+ }
65
+ },
66
+ load(id) {
67
+ var _a;
68
+ if (((_a = getMeta(this, id)) === null || _a === void 0 ? void 0 : _a.type) === 'template-only-component-js') {
69
+ this.addWatchFile(id);
70
+ return {
71
+ code: (0, core_1.templateOnlyComponentSource)(),
72
+ };
73
+ }
74
+ },
75
+ transform: {
76
+ // Enforce running the hbs transform before any others like babel that expect valid JS
77
+ order: 'pre',
78
+ handler(code, id) {
79
+ var _a;
80
+ let hbsFilename = id.replace(/\.\w{1,3}$/, '') + '.hbs';
81
+ if (hbsFilename !== id) {
82
+ this.addWatchFile(hbsFilename);
83
+ if (((_a = getMeta(this, id)) === null || _a === void 0 ? void 0 : _a.type) === 'template-only-component-js') {
84
+ this.addWatchFile(id);
85
+ }
86
+ }
87
+ if (!hbsFilter(id)) {
88
+ return null;
89
+ }
90
+ return (0, core_1.hbsToJS)(code);
91
+ },
92
+ },
93
+ };
94
+ }
95
+ function getMeta(context, id) {
96
+ var _a, _b;
97
+ const meta = (_b = (_a = context.getModuleInfo(id)) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b['rollup-hbs-plugin'];
98
+ if (meta) {
99
+ return meta;
100
+ }
101
+ else {
102
+ return null;
103
+ }
104
+ }
105
+ //# sourceMappingURL=rollup-hbs-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup-hbs-plugin.js","sourceRoot":"","sources":["rollup-hbs-plugin.ts"],"names":[],"mappings":";;;;;AAaA,kCA6FC;AAzGD,qDAAmD;AACnD,0DAAkC;AAClC,0CAKyB;AACzB,+BAA+B;AAE/B,MAAM,SAAS,GAAG,IAAA,0BAAY,EAAC,iBAAiB,CAAC,CAAC;AAElD,SAAwB,eAAe,CAAC,EACtC,iBAAiB,GAGlB;IACC,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,KAAK,CAAC,SAAS,CAAC,MAAc,EAAE,QAA4B,EAAE,OAAO;;YACnE,IAAI,MAAA,MAAA,OAAO,CAAC,MAAM,0CAAE,SAAS,0CAAE,iBAAiB,EAAE,CAAC;gBACjD,OAAO,IAAI,CAAC;YACd,CAAC;YAED,IAAI,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE;gBACpD,GAAG,OAAO;gBACV,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;YAEH,IAAI,CAAC,UAAU,IAAI,IAAA,cAAO,EAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;gBAC1C,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE;oBACzD,GAAG,OAAO;oBACV,QAAQ,EAAE,IAAI;iBACf,CAAC,CAAC;YACL,CAAC;YAED,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,IAAI,SAAS,GAAG,IAAA,uBAAgB,EAAC,MAAM,CAAC,CAAC;gBACzC,IAAI,SAAS,EAAE,CAAC;oBACd,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE;wBACnD,GAAG,OAAO;wBACV,QAA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AI,WAAW,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC;gBACxD,IAAI,WAAW,KAAK,EAAE,EAAE,CAAC;oBACvB,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;oBAC/B,IAAI,CAAA,MAAA,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,0CAAE,IAAI,MAAK,4BAA4B,EAAE,CAAC;wBAC7D,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;oBACxB,CAAC;gBACH,CAAC;gBACD,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;oBACnB,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;YACvB,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAMD,SAAS,OAAO,CAAC,OAAsB,EAAE,EAAU;;IACjD,MAAM,IAAI,GAAG,MAAA,MAAA,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,0CAAE,IAAI,0CAAG,mBAAmB,CAAC,CAAC;IACpE,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAY,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { Plugin, PluginContext } from 'rollup';\nimport { createFilter } from '@rollup/pluginutils';\nimport minimatch from 'minimatch';\nimport {\n hbsToJS,\n templateOnlyComponentSource,\n needsSyntheticComponentJS,\n syntheticJStoHBS,\n} from '@embroider/core';\nimport { extname } from 'path';\n\nconst hbsFilter = createFilter('**/*.hbs?([?]*)');\n\nexport default function rollupHbsPlugin({\n excludeColocation,\n}: {\n excludeColocation?: string[];\n}): Plugin {\n return {\n name: 'rollup-hbs-plugin',\n async resolveId(source: string, importer: string | undefined, options) {\n if (options.custom?.embroider?.isExtensionSearch) {\n return null;\n }\n\n let resolution = await this.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n\n if (!resolution && extname(source) === '') {\n resolution = await this.resolve(source + '.hbs', importer, {\n ...options,\n skipSelf: true,\n });\n }\n\n if (!resolution) {\n let hbsSource = syntheticJStoHBS(source);\n if (hbsSource) {\n resolution = await this.resolve(hbsSource, importer, {\n ...options,\n skipSelf: true,\n custom: {\n embroider: {\n isExtensionSearch: true,\n },\n },\n });\n }\n\n if (!resolution) {\n return null;\n }\n }\n\n if (resolution && resolution.id.endsWith('.hbs')) {\n let isExcluded = excludeColocation?.some((glob) =>\n minimatch(resolution!.id, glob)\n );\n if (isExcluded) {\n return resolution;\n }\n }\n\n let syntheticId = needsSyntheticComponentJS(source, resolution.id);\n if (syntheticId) {\n this.addWatchFile(source);\n return {\n id: syntheticId,\n meta: {\n 'rollup-hbs-plugin': {\n type: 'template-only-component-js',\n },\n },\n };\n }\n },\n\n load(id: string) {\n if (getMeta(this, id)?.type === 'template-only-component-js') {\n this.addWatchFile(id);\n return {\n code: templateOnlyComponentSource(),\n };\n }\n },\n\n transform: {\n // Enforce running the hbs transform before any others like babel that expect valid JS\n order: 'pre',\n handler(code: string, id: string) {\n let hbsFilename = id.replace(/\\.\\w{1,3}$/, '') + '.hbs';\n if (hbsFilename !== id) {\n this.addWatchFile(hbsFilename);\n if (getMeta(this, id)?.type === 'template-only-component-js') {\n this.addWatchFile(id);\n }\n }\n if (!hbsFilter(id)) {\n return null;\n }\n return hbsToJS(code);\n },\n },\n };\n}\n\ntype Meta = {\n type: 'template-only-component-js';\n};\n\nfunction getMeta(context: PluginContext, id: string): Meta | null {\n const meta = context.getModuleInfo(id)?.meta?.['rollup-hbs-plugin'];\n if (meta) {\n return meta as Meta;\n } else {\n return null;\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'rollup';
2
+ export default function incremental(): Plugin;
3
+ //# sourceMappingURL=rollup-incremental-plugin.d.ts.map