@embroider/addon-dev 8.3.1 → 8.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/addon-dev",
3
- "version": "8.3.1",
3
+ "version": "8.4.0",
4
4
  "description": "Utilities for addon authors",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  "rollup-plugin-copy-assets": "^2.0.3",
41
41
  "walk-sync": "^3.0.0",
42
42
  "yargs": "^17.0.1",
43
- "@embroider/core": "^4.6.2"
43
+ "@embroider/core": "^4.6.6"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@glimmer/syntax": "^0.94.9",
@@ -94,22 +94,41 @@ async function fixDeclarationsInMatchingFiles(dir) {
94
94
  return;
95
95
  }
96
96
  const dtsFiles = (0, walk_sync_1.default)(dir, {
97
- globs: ['**/*.d.ts'],
97
+ globs: ['**/*.d.ts', '**/*.d.gts.ts', '**/*.d.gjs.ts'],
98
98
  directories: false,
99
99
  includeBasePath: true,
100
100
  });
101
101
  return Promise.all(dtsFiles.map(async (file) => {
102
- const content = await (0, promises_1.readFile)(file, { encoding: 'utf8' });
103
- await (0, promises_1.writeFile)(file, fixDeclarations(content));
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));
104
120
  }));
105
121
  }
106
- // Strip any .gts extension from imports in d.ts files, as these won't resolve. See https://github.com/typed-ember/glint/issues/628
107
- // Once Glint v2 is available, this shouldn't be needed anymore.
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
108
127
  function fixDeclarations(content) {
109
128
  return content
110
- .replace(/from\s+'([^']+)\.gts'/g, `from '$1'`)
111
- .replace(/from\s+"([^"]+)\.gts"/g, `from '$1'`)
112
- .replace(/import\("([^"]+)\.gts"\)/g, `import('$1')`)
113
- .replace(/import\('([^']+)\.gts'\)/g, `import('$1')`);
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')`);
114
133
  }
115
134
  //# sourceMappingURL=rollup-declarations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-declarations.js","sourceRoot":"","sources":["rollup-declarations.ts"],"names":[],"mappings":";;;;;AAUA,2CA0FC;AAnGD,kDAA0B;AAC1B,0DAAiC;AACjC,0CAAkD;AAClD,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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AAO,CAAC,wBAAwB,EAAE,WAAW,CAAC;SAC9C,OAAO,CAAC,2BAA2B,EAAE,cAAc,CAAC;SACpD,OAAO,CAAC,2BAA2B,EAAE,cAAc,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import type { Plugin } from 'rollup';\nimport execa from 'execa';\nimport walkSync from 'walk-sync';\nimport { readFile, 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'],\n directories: false,\n includeBasePath: true,\n });\n\n return Promise.all(\n dtsFiles.map(async (file) => {\n const content = await readFile(file, { encoding: 'utf8' });\n\n await writeFile(file, fixDeclarations(content));\n })\n );\n}\n\n// Strip any .gts extension from imports in d.ts files, as these won't resolve. See https://github.com/typed-ember/glint/issues/628\n// Once Glint v2 is available, this shouldn't be needed anymore.\nfunction fixDeclarations(content: string) {\n return content\n .replace(/from\\s+'([^']+)\\.gts'/g, `from '$1'`)\n .replace(/from\\s+\"([^\"]+)\\.gts\"/g, `from '$1'`)\n .replace(/import\\(\"([^\"]+)\\.gts\"\\)/g, `import('$1')`)\n .replace(/import\\('([^']+)\\.gts'\\)/g, `import('$1')`);\n}\n"]}
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,YA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GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;QAE1D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,MAAM,IAAA,iBAAM,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;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"]}