@embroider/core 0.46.1 → 0.47.2

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 (42) hide show
  1. package/package.json +4 -4
  2. package/src/app-files.js +5 -3
  3. package/src/app-files.js.map +1 -1
  4. package/src/app.js +27 -8
  5. package/src/app.js.map +1 -1
  6. package/src/babel-plugin-adjust-imports.d.ts +6 -5
  7. package/src/babel-plugin-adjust-imports.js.map +1 -1
  8. package/src/babel-plugin-inline-hbs-deps-node.d.ts +14 -0
  9. package/src/babel-plugin-inline-hbs-deps-node.js +27 -0
  10. package/src/babel-plugin-inline-hbs-deps-node.js.map +1 -0
  11. package/src/babel-plugin-inline-hbs-deps.d.ts +10 -0
  12. package/src/babel-plugin-inline-hbs-deps.js +119 -0
  13. package/src/babel-plugin-inline-hbs-deps.js.map +1 -0
  14. package/src/babel-plugin-inline-hbs-node.d.ts +3 -9
  15. package/src/babel-plugin-inline-hbs-node.js.map +1 -1
  16. package/src/babel-plugin-inline-hbs.d.ts +5 -7
  17. package/src/babel-plugin-inline-hbs.js +35 -73
  18. package/src/babel-plugin-inline-hbs.js.map +1 -1
  19. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +12 -0
  20. package/src/babel-plugin-stage1-inline-hbs-node.js +9 -0
  21. package/src/babel-plugin-stage1-inline-hbs-node.js.map +1 -0
  22. package/src/babel-plugin-stage1-inline-hbs.d.ts +9 -0
  23. package/src/babel-plugin-stage1-inline-hbs.js +96 -0
  24. package/src/babel-plugin-stage1-inline-hbs.js.map +1 -0
  25. package/src/describe-exports.js +3 -3
  26. package/src/describe-exports.js.map +1 -1
  27. package/src/mini-modules-polyfill.d.ts +1 -1
  28. package/src/mini-modules-polyfill.js.map +1 -1
  29. package/src/patch-template-compiler.js +3 -4
  30. package/src/patch-template-compiler.js.map +1 -1
  31. package/src/rename-require-plugin.js.map +1 -1
  32. package/src/template-compiler-common.d.ts +3 -1
  33. package/src/template-compiler-common.js +8 -12
  34. package/src/template-compiler-common.js.map +1 -1
  35. package/src/template-compiler-node.js +3 -3
  36. package/src/template-compiler-node.js.map +1 -1
  37. package/src/babel-import-adder.d.ts +0 -11
  38. package/src/babel-import-adder.js +0 -75
  39. package/src/babel-import-adder.js.map +0 -1
  40. package/src/template-colocation-plugin.d.ts +0 -22
  41. package/src/template-colocation-plugin.js +0 -113
  42. package/src/template-colocation-plugin.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-adjust-imports.js","sourceRoot":"","sources":["babel-plugin-adjust-imports.ts"],"names":[],"mappings":";;;;;;;;;AAAA,kEAAwH;AACxH,+BAA8C;AAG9C,kEAAiG;AACjG,uCAA0C;AAC1C,2DAA6C;AAC7C,mDAA0C;AAC1C,mEAAkE;AAmClE,MAAM,YAAY,GAAG,+BAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAQ7D,SAAgB,sBAAsB,CAAC,CAAa,EAAE,IAAmB;IACvE,IACE,CAAC,IAAI;QACL,CAAC,IAAI,CAAC,gBAAgB,EAAE;QACxB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY;QACtC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,EACvE;QACA,OAAO,KAAK,CAAC;KACd;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC;AAZD,wDAYC;AAED,SAAgB,yBAAyB,CAAC,CAAa,EAAE,IAAmB;IAC1E,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,MAA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C,IAAI,CAAC,CAAC;SAC5C;IACH,CAAC;CACF;AAVC;IADC,IAAA,4BAAO,GAAE;+CAGT;AAGD;IADC,IAAA,4BAAO,GAAE;sDAKT;AAGH,SAAS,UAAU,CAAC,KAAY;IAC9B,IAAI,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACrB,IAAI,0BAA0B,IAAI,IAAI,EAAE;QACtC,iEAAiE;QACjE,OAAO,CAAC,KAAK,CAAC,IAAI,mCAAQ,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,GAAK,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAE,CAAC,CAAC;KAC1G;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,8EAA8E;AAC9E,mEAAmE;AACnE,8EAA8E;AAC9E,4EAA4E;AAC5E,qCAAqC;AACrC,SAAS,kBAAkB,CAAC,GAAc,EAAE,WAAmB;IAC7D,IAAI,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE;QAClC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE;QACvD,OAAO,IAAI,CAAC;KACb;IAED,IAAI,uCAAoB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;QACzC,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { emberVirtualPackages, emberVirtualPeerDeps, packageName as getPackageName } from '@embroider/shared-internals';\nimport { join, dirname, resolve } from 'path';\nimport type { NodePath } from '@babel/traverse';\nimport type * as t from '@babel/types';\nimport { PackageCache, Package, V2Package, explicitRelative } from '@embroider/shared-internals';\nimport { outputFileSync } from 'fs-extra';\nimport { Memoize } from 'typescript-memoize';\nimport { compile } from './js-handlebars';\nimport { handleImportDeclaration } from './mini-modules-polyfill';\n\ninterface State {\n adjustFile: AdjustFile;\n opts: Options | DeflatedOptions;\n}\n\nexport interface DeflatedOptions {\n adjustImportsOptionsPath: string;\n relocatedFilesPath: string;\n}\n\ntype BabelTypes = typeof t;\n\nexport interface Options {\n renamePackages: {\n [fromName: string]: string;\n };\n renameModules: {\n [fromName: string]: string;\n };\n extraImports: {\n absPath: string;\n target: string;\n runtimeName?: string;\n }[];\n externalsDir: string;\n activeAddons: {\n [packageName: string]: string;\n };\n relocatedFiles: { [relativePath: string]: string };\n resolvableExtensions: string[];\n emberNeedsModulesPolyfill: boolean;\n}\n\nconst packageCache = PackageCache.shared('embroider-stage3');\n\ntype DefineExpressionPath = NodePath<t.CallExpression> & {\n node: t.CallExpression & {\n arguments: [t.StringLiteral, t.ArrayExpression, Function];\n };\n};\n\nexport function isImportSyncExpression(t: BabelTypes, path: NodePath<any>) {\n if (\n !path ||\n !path.isCallExpression() ||\n path.node.callee.type !== 'Identifier' ||\n !path.get('callee').referencesImport('@embroider/macros', 'importSync')\n ) {\n return false;\n }\n\n const args = path.node.arguments;\n return Array.isArray(args) && args.length === 1 && t.isStringLiteral(args[0]);\n}\n\nexport function isDynamicImportExpression(t: BabelTypes, path: NodePath<any>) {\n if (!path || !path.isCallExpression() || path.node.callee.type !== 'Import') {\n return false;\n }\n\n const args = path.node.arguments;\n return Array.isArray(args) && args.length === 1 && t.isStringLiteral(args[0]);\n}\n\nexport function isDefineExpression(t: BabelTypes, path: NodePath<any>): path is DefineExpressionPath {\n // should we allow nested defines, or stop at the top level?\n if (!path.isCallExpression() || path.node.callee.type !== 'Identifier' || path.node.callee.name !== 'define') {\n return false;\n }\n\n const args = path.node.arguments;\n\n // only match define with 3 arguments define(name: string, deps: string[], cb: Function);\n return (\n Array.isArray(args) &&\n args.length === 3 &&\n t.isStringLiteral(args[0]) &&\n t.isArrayExpression(args[1]) &&\n t.isFunction(args[2])\n );\n}\n\nfunction adjustSpecifier(specifier: string, file: AdjustFile, opts: Options, isDynamic: boolean) {\n if (specifier === '@embroider/macros') {\n // the macros package is always handled directly within babel (not\n // necessarily as a real resolvable package), so we should not mess with it.\n // It might not get compiled away until *after* our plugin has run, which is\n // why we need to know about it.\n return specifier;\n }\n\n specifier = handleRenaming(specifier, file, opts);\n specifier = handleExternal(specifier, file, opts, isDynamic);\n return specifier;\n}\n\nfunction handleRenaming(specifier: string, sourceFile: AdjustFile, opts: Options) {\n let packageName = getPackageName(specifier);\n if (!packageName) {\n return specifier;\n }\n\n for (let [candidate, replacement] of Object.entries(opts.renameModules)) {\n if (candidate === specifier) {\n return replacement;\n }\n for (let extension of opts.resolvableExtensions) {\n if (candidate === specifier + '/index' + extension) {\n return replacement;\n }\n if (candidate === specifier + extension) {\n return replacement;\n }\n }\n }\n\n if (opts.renamePackages[packageName]) {\n return specifier.replace(packageName, opts.renamePackages[packageName]);\n }\n\n let pkg = sourceFile.owningPackage();\n if (!pkg || !pkg.isV2Ember()) {\n return specifier;\n }\n\n if (pkg.meta['auto-upgraded'] && pkg.name === packageName) {\n // we found a self-import, make it relative. Only auto-upgraded packages get\n // this help, v2 packages are natively supposed to use relative imports for\n // their own modules, and we want to push them all to do that correctly.\n let fullPath = specifier.replace(packageName, pkg.root);\n return explicitRelative(dirname(sourceFile.name), fullPath);\n }\n\n let relocatedIntoPkg = sourceFile.relocatedIntoPackage();\n if (relocatedIntoPkg && pkg.meta['auto-upgraded'] && relocatedIntoPkg.name === packageName) {\n // a file that was relocated into a package does a self-import of that\n // package's name. This can happen when an addon (like ember-cli-mirage)\n // emits files from its own treeForApp that contain imports of the app's own\n // fully qualified name.\n let fullPath = specifier.replace(packageName, relocatedIntoPkg.root);\n return explicitRelative(dirname(sourceFile.name), fullPath);\n }\n\n return specifier;\n}\n\nfunction isExplicitlyExternal(specifier: string, fromPkg: V2Package): boolean {\n return Boolean(fromPkg.isV2Addon() && fromPkg.meta['externals'] && fromPkg.meta['externals'].includes(specifier));\n}\n\nfunction isResolvable(packageName: string, fromPkg: Package): false | Package {\n try {\n let dep = packageCache.resolve(packageName, fromPkg);\n if (!dep.isEmberPackage() && !fromPkg.hasDependency('ember-auto-import')) {\n return false;\n }\n return dep;\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n return false;\n }\n}\n\nconst dynamicMissingModule = compile(`\n throw new Error('Could not find module \\`{{{js-string-escape moduleName}}}\\`');\n`) as (params: { moduleName: string }) => string;\n\nconst externalTemplate = compile(`\n{{#if (eq runtimeName \"require\")}}\nconst m = window.requirejs;\n{{else}}\nconst m = window.require(\"{{{js-string-escape runtimeName}}}\");\n{{/if}}\n{{!-\n There are plenty of hand-written AMD defines floating around\n that lack this, and they will break when other build systems\n encounter them.\n\n As far as I can tell, Ember's loader was already treating this\n case as a module, so in theory we aren't breaking anything by\n marking it as such when other packagers come looking.\n\n todo: get review on this part.\n-}}\nif (m.default && !m.__esModule) {\n m.__esModule = true;\n}\nmodule.exports = m;\n`) as (params: { runtimeName: string }) => string;\n\nfunction handleExternal(specifier: string, sourceFile: AdjustFile, opts: Options, isDynamic: boolean): string {\n let pkg = sourceFile.owningPackage();\n if (!pkg || !pkg.isV2Ember()) {\n return specifier;\n }\n\n let packageName = getPackageName(specifier);\n if (!packageName) {\n // This is a relative import. We don't automatically externalize those\n // because it's rare, and by keeping them static we give better errors. But\n // we do allow them to be explicitly externalized by the package author (or\n // a compat adapter). In the metadata, they would be listed in\n // package-relative form, so we need to convert this specifier to that.\n let absoluteSpecifier = resolve(dirname(sourceFile.name), specifier);\n let packageRelativeSpecifier = explicitRelative(pkg.root, absoluteSpecifier);\n if (isExplicitlyExternal(packageRelativeSpecifier, pkg)) {\n let publicSpecifier = absoluteSpecifier.replace(pkg.root, pkg.name);\n return makeExternal(publicSpecifier, sourceFile, opts);\n } else {\n return specifier;\n }\n }\n\n // absolute package imports can also be explicitly external based on their\n // full specifier name\n if (isExplicitlyExternal(specifier, pkg)) {\n return makeExternal(specifier, sourceFile, opts);\n }\n\n let relocatedPkg = sourceFile.relocatedIntoPackage();\n if (relocatedPkg) {\n // this file has been moved into another package (presumably the app).\n\n // self-imports are legal in the app tree, even for v2 packages\n if (packageName === pkg.name) {\n return specifier;\n }\n\n // first try to resolve from the destination package\n if (isResolvable(packageName, relocatedPkg)) {\n if (!pkg.meta['auto-upgraded']) {\n throw new Error(\n `${pkg.name} is trying to import ${packageName} from within its app tree. This is unsafe, because ${pkg.name} can't control which dependencies are resolvable from the app`\n );\n }\n return specifier;\n } else {\n // second try to resolve from the source package\n let targetPkg = isResolvable(packageName, pkg);\n if (targetPkg) {\n if (!pkg.meta['auto-upgraded']) {\n throw new Error(\n `${pkg.name} is trying to import ${packageName} from within its app tree. This is unsafe, because ${pkg.name} can't control which dependencies are resolvable from the app`\n );\n }\n // we found it, but we need to rewrite it because it's not really going to\n // resolve from where its sitting\n return explicitRelative(dirname(sourceFile.name), specifier.replace(packageName, targetPkg.root));\n }\n }\n } else {\n if (isResolvable(packageName, pkg)) {\n if (!pkg.meta['auto-upgraded'] && !reliablyResolvable(pkg, packageName)) {\n throw new Error(\n `${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`\n );\n }\n return specifier;\n }\n }\n\n // auto-upgraded packages can fall back to the set of known active addons\n if (pkg.meta['auto-upgraded'] && opts.activeAddons[packageName]) {\n return explicitRelative(dirname(sourceFile.name), specifier.replace(packageName, opts.activeAddons[packageName]));\n }\n\n // auto-upgraded packages can fall back to attmpeting to find dependencies at\n // runtime. Native v2 packages can only get this behavior in the\n // isExplicitlyExternal case above because they need to explicitly ask for\n // externals.\n if (pkg.meta['auto-upgraded']) {\n return makeExternal(specifier, sourceFile, opts);\n }\n\n if (pkg.isV2Ember()) {\n // native v2 packages don't automatically externalize *everything* the way\n // auto-upgraded packages do, but they still externalize known and approved\n // ember virtual packages (like @ember/component)\n if (emberVirtualPackages.has(packageName)) {\n return makeExternal(specifier, sourceFile, opts);\n }\n\n // native v2 packages don't automatically get to use every other addon as a\n // peerDep, but they do get the known and approved ember virtual peer deps,\n // like @glimmer/component\n if (emberVirtualPeerDeps.has(packageName)) {\n if (!opts.activeAddons[packageName]) {\n throw new Error(\n `${pkg.name} is trying to import from ${packageName}, which is supposed to be present in all ember apps but seems to be missing`\n );\n }\n return explicitRelative(dirname(sourceFile.name), specifier.replace(packageName, opts.activeAddons[packageName]));\n }\n }\n\n // non-resolvable imports in dynamic positions become runtime errors, not\n // build-time errors, so we emit the runtime error module here before the\n // stage3 packager has a chance to see the missing module. (Maybe some stage3\n // packagers will have this behavior by default, because it would make sense,\n // but webpack at least does not.)\n if (isDynamic) {\n return makeMissingModule(specifier, sourceFile, opts);\n }\n\n // this is falling through with the original specifier which was\n // non-resolvable, which will presumably cause a static build error in stage3.\n return specifier;\n}\n\nfunction makeMissingModule(specifier: string, sourceFile: AdjustFile, opts: Options): string {\n let target = join(opts.externalsDir, specifier + '.js');\n outputFileSync(\n target,\n dynamicMissingModule({\n moduleName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile.name), target.slice(0, -3));\n}\n\nfunction makeExternal(specifier: string, sourceFile: AdjustFile, opts: Options): string {\n let target = join(opts.externalsDir, specifier + '.js');\n outputFileSync(\n target,\n externalTemplate({\n runtimeName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile.name), target.slice(0, -3));\n}\n\nexport default function main(babel: unknown) {\n let t = (babel as any).types as BabelTypes;\n return {\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n let opts = ensureOpts(state);\n state.adjustFile = new AdjustFile(path.hub.file.opts.filename, opts.relocatedFiles);\n addExtraImports(t, path, opts.extraImports);\n },\n exit(path: NodePath<t.Program>, state: State) {\n for (let child of path.get('body')) {\n if (child.isImportDeclaration() || child.isExportNamedDeclaration() || child.isExportAllDeclaration()) {\n rewriteTopLevelImport(t, child, state);\n }\n }\n },\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State) {\n if (isImportSyncExpression(t, path) || isDynamicImportExpression(t, path)) {\n const [source] = path.get('arguments');\n let opts = ensureOpts(state);\n let specifier = adjustSpecifier((source.node as any).value, state.adjustFile, opts, true);\n source.replaceWith(t.stringLiteral(specifier));\n return;\n }\n\n // Should/can we make this early exit when the first define was found?\n if (!isDefineExpression(t, path)) {\n return;\n }\n\n let pkg = state.adjustFile.owningPackage();\n if (pkg && pkg.isV2Ember() && !pkg.meta['auto-upgraded']) {\n throw new Error(\n `The file ${state.adjustFile.originalFile} in package ${pkg.name} tried to use AMD define. Native V2 Ember addons are forbidden from using AMD define, they must use ECMA export only.`\n );\n }\n\n let opts = ensureOpts(state);\n\n const dependencies = path.node.arguments[1];\n\n const specifiers = dependencies.elements.slice();\n specifiers.push(path.node.arguments[0]);\n\n for (let source of specifiers) {\n if (!source) {\n continue;\n }\n\n if (source.type !== 'StringLiteral') {\n throw path.buildCodeFrameError(`expected only string literal arguments`);\n }\n\n if (source.value === 'exports' || source.value === 'require') {\n // skip \"special\" AMD dependencies\n continue;\n }\n\n let specifier = adjustSpecifier(source.value, state.adjustFile, opts, false);\n\n if (specifier !== source.value) {\n source.value = specifier;\n }\n }\n },\n },\n };\n}\n\nfunction rewriteTopLevelImport(\n t: BabelTypes,\n path: NodePath<t.ImportDeclaration | t.ExportNamedDeclaration | t.ExportAllDeclaration>,\n state: State\n) {\n let opts = ensureOpts(state);\n const { source } = path.node;\n if (source === null || source === undefined) {\n return;\n }\n\n if (opts.emberNeedsModulesPolyfill && path.isImportDeclaration()) {\n let replacement = handleImportDeclaration(t, path);\n if (replacement) {\n path.replaceWith(replacement);\n return;\n }\n }\n\n let specifier = adjustSpecifier(source.value, state.adjustFile, opts, false);\n if (specifier !== source.value) {\n source.value = specifier;\n }\n}\n\n(main as any).baseDir = function () {\n return join(__dirname, '..');\n};\n\nfunction addExtraImports(t: BabelTypes, path: NodePath<t.Program>, extraImports: Required<Options>['extraImports']) {\n let counter = 0;\n for (let { absPath, target, runtimeName } of extraImports) {\n if (absPath === path.hub.file.opts.filename) {\n if (runtimeName) {\n path.node.body.unshift(amdDefine(t, runtimeName, counter));\n path.node.body.unshift(\n t.importDeclaration([t.importNamespaceSpecifier(t.identifier(`a${counter++}`))], t.stringLiteral(target))\n );\n } else {\n path.node.body.unshift(t.importDeclaration([], t.stringLiteral(target)));\n }\n }\n }\n}\n\nfunction amdDefine(t: BabelTypes, runtimeName: string, importCounter: number) {\n return t.expressionStatement(\n t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [\n t.stringLiteral(runtimeName),\n t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),\n ])\n );\n}\n\nclass AdjustFile {\n readonly originalFile: string;\n\n constructor(public name: string, relocatedFiles: Options['relocatedFiles']) {\n if (!name) {\n throw new Error(`bug: adjust-imports plugin was run without a filename`);\n }\n this.originalFile = relocatedFiles[name] || name;\n }\n\n get isRelocated() {\n return this.originalFile !== this.name;\n }\n\n @Memoize()\n owningPackage(): Package | undefined {\n return packageCache.ownerOfFile(this.originalFile);\n }\n\n @Memoize()\n relocatedIntoPackage(): Package | undefined {\n if (this.isRelocated) {\n return packageCache.ownerOfFile(this.name);\n }\n }\n}\n\nfunction ensureOpts(state: State): Options {\n let { opts } = state;\n if ('adjustImportsOptionsPath' in opts) {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n return (state.opts = { ...require(opts.adjustImportsOptionsPath), ...require(opts.relocatedFilesPath) });\n }\n return opts;\n}\n\n// we don't want to allow things that resolve only by accident that are likely\n// to break in other setups. For example: import your dependencies'\n// dependencies, or importing your own name from within a monorepo (which will\n// work because of the symlinking) without setting up \"exports\" (which makes\n// your own name reliably resolvable)\nfunction reliablyResolvable(pkg: V2Package, packageName: string) {\n if (pkg.hasDependency(packageName)) {\n return true;\n }\n\n if (pkg.name === packageName && pkg.packageJSON.exports) {\n return true;\n }\n\n if (emberVirtualPeerDeps.has(packageName)) {\n return true;\n }\n\n return false;\n}\n"]}
1
+ {"version":3,"file":"babel-plugin-adjust-imports.js","sourceRoot":"","sources":["babel-plugin-adjust-imports.ts"],"names":[],"mappings":";;;;;;;;;AAAA,kEAAwH;AACxH,+BAA8C;AAI9C,kEAAiG;AACjG,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d,CAAC;AAED,8EAA8E;AAC9E,mEAAmE;AACnE,8EAA8E;AAC9E,4EAA4E;AAC5E,qCAAqC;AACrC,SAAS,kBAAkB,CAAC,GAAc,EAAE,WAAmB;IAC7D,IAAI,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE;QAClC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE;QACvD,OAAO,IAAI,CAAC;KACb;IAED,IAAI,uCAAoB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;QACzC,OAAO,IAAI,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { emberVirtualPackages, emberVirtualPeerDeps, packageName as getPackageName } from '@embroider/shared-internals';\nimport { join, dirname, resolve } from 'path';\nimport type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { PackageCache, Package, V2Package, explicitRelative } from '@embroider/shared-internals';\nimport { outputFileSync } from 'fs-extra';\nimport { Memoize } from 'typescript-memoize';\nimport { compile } from './js-handlebars';\nimport { handleImportDeclaration } from './mini-modules-polyfill';\n\ninterface State {\n adjustFile: AdjustFile;\n opts: Options | DeflatedOptions;\n}\n\nexport interface DeflatedOptions {\n adjustImportsOptionsPath: string;\n relocatedFilesPath: string;\n}\n\ntype BabelTypes = typeof t;\n\nexport interface Options {\n renamePackages: {\n [fromName: string]: string;\n };\n renameModules: {\n [fromName: string]: string;\n };\n extraImports: {\n absPath: string;\n target: string;\n runtimeName?: string;\n }[];\n externalsDir: string;\n activeAddons: {\n [packageName: string]: string;\n };\n relocatedFiles: { [relativePath: string]: string };\n resolvableExtensions: string[];\n emberNeedsModulesPolyfill: boolean;\n}\n\nconst packageCache = PackageCache.shared('embroider-stage3');\n\ntype DefineExpressionPath = NodePath<t.CallExpression> & {\n node: t.CallExpression & {\n arguments: [t.StringLiteral, t.ArrayExpression, Function];\n };\n};\n\nexport function isImportSyncExpression(t: BabelTypes, path: NodePath<any>) {\n if (\n !path ||\n !path.isCallExpression() ||\n path.node.callee.type !== 'Identifier' ||\n !path.get('callee').referencesImport('@embroider/macros', 'importSync')\n ) {\n return false;\n }\n\n const args = path.node.arguments;\n return Array.isArray(args) && args.length === 1 && t.isStringLiteral(args[0]);\n}\n\nexport function isDynamicImportExpression(t: BabelTypes, path: NodePath<any>) {\n if (!path || !path.isCallExpression() || path.node.callee.type !== 'Import') {\n return false;\n }\n\n const args = path.node.arguments;\n return Array.isArray(args) && args.length === 1 && t.isStringLiteral(args[0]);\n}\n\nexport function isDefineExpression(t: BabelTypes, path: NodePath<any>): path is DefineExpressionPath {\n // should we allow nested defines, or stop at the top level?\n if (!path.isCallExpression() || path.node.callee.type !== 'Identifier' || path.node.callee.name !== 'define') {\n return false;\n }\n\n const args = path.node.arguments;\n\n // only match define with 3 arguments define(name: string, deps: string[], cb: Function);\n return (\n Array.isArray(args) &&\n args.length === 3 &&\n t.isStringLiteral(args[0]) &&\n t.isArrayExpression(args[1]) &&\n t.isFunction(args[2])\n );\n}\n\nfunction adjustSpecifier(specifier: string, file: AdjustFile, opts: Options, isDynamic: boolean) {\n if (specifier === '@embroider/macros') {\n // the macros package is always handled directly within babel (not\n // necessarily as a real resolvable package), so we should not mess with it.\n // It might not get compiled away until *after* our plugin has run, which is\n // why we need to know about it.\n return specifier;\n }\n\n specifier = handleRenaming(specifier, file, opts);\n specifier = handleExternal(specifier, file, opts, isDynamic);\n return specifier;\n}\n\nfunction handleRenaming(specifier: string, sourceFile: AdjustFile, opts: Options) {\n let packageName = getPackageName(specifier);\n if (!packageName) {\n return specifier;\n }\n\n for (let [candidate, replacement] of Object.entries(opts.renameModules)) {\n if (candidate === specifier) {\n return replacement;\n }\n for (let extension of opts.resolvableExtensions) {\n if (candidate === specifier + '/index' + extension) {\n return replacement;\n }\n if (candidate === specifier + extension) {\n return replacement;\n }\n }\n }\n\n if (opts.renamePackages[packageName]) {\n return specifier.replace(packageName, opts.renamePackages[packageName]);\n }\n\n let pkg = sourceFile.owningPackage();\n if (!pkg || !pkg.isV2Ember()) {\n return specifier;\n }\n\n if (pkg.meta['auto-upgraded'] && pkg.name === packageName) {\n // we found a self-import, make it relative. Only auto-upgraded packages get\n // this help, v2 packages are natively supposed to use relative imports for\n // their own modules, and we want to push them all to do that correctly.\n let fullPath = specifier.replace(packageName, pkg.root);\n return explicitRelative(dirname(sourceFile.name), fullPath);\n }\n\n let relocatedIntoPkg = sourceFile.relocatedIntoPackage();\n if (relocatedIntoPkg && pkg.meta['auto-upgraded'] && relocatedIntoPkg.name === packageName) {\n // a file that was relocated into a package does a self-import of that\n // package's name. This can happen when an addon (like ember-cli-mirage)\n // emits files from its own treeForApp that contain imports of the app's own\n // fully qualified name.\n let fullPath = specifier.replace(packageName, relocatedIntoPkg.root);\n return explicitRelative(dirname(sourceFile.name), fullPath);\n }\n\n return specifier;\n}\n\nfunction isExplicitlyExternal(specifier: string, fromPkg: V2Package): boolean {\n return Boolean(fromPkg.isV2Addon() && fromPkg.meta['externals'] && fromPkg.meta['externals'].includes(specifier));\n}\n\nfunction isResolvable(packageName: string, fromPkg: Package): false | Package {\n try {\n let dep = packageCache.resolve(packageName, fromPkg);\n if (!dep.isEmberPackage() && !fromPkg.hasDependency('ember-auto-import')) {\n return false;\n }\n return dep;\n } catch (err) {\n if (err.code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n return false;\n }\n}\n\nconst dynamicMissingModule = compile(`\n throw new Error('Could not find module \\`{{{js-string-escape moduleName}}}\\`');\n`) as (params: { moduleName: string }) => string;\n\nconst externalTemplate = compile(`\n{{#if (eq runtimeName \"require\")}}\nconst m = window.requirejs;\n{{else}}\nconst m = window.require(\"{{{js-string-escape runtimeName}}}\");\n{{/if}}\n{{!-\n There are plenty of hand-written AMD defines floating around\n that lack this, and they will break when other build systems\n encounter them.\n\n As far as I can tell, Ember's loader was already treating this\n case as a module, so in theory we aren't breaking anything by\n marking it as such when other packagers come looking.\n\n todo: get review on this part.\n-}}\nif (m.default && !m.__esModule) {\n m.__esModule = true;\n}\nmodule.exports = m;\n`) as (params: { runtimeName: string }) => string;\n\nfunction handleExternal(specifier: string, sourceFile: AdjustFile, opts: Options, isDynamic: boolean): string {\n let pkg = sourceFile.owningPackage();\n if (!pkg || !pkg.isV2Ember()) {\n return specifier;\n }\n\n let packageName = getPackageName(specifier);\n if (!packageName) {\n // This is a relative import. We don't automatically externalize those\n // because it's rare, and by keeping them static we give better errors. But\n // we do allow them to be explicitly externalized by the package author (or\n // a compat adapter). In the metadata, they would be listed in\n // package-relative form, so we need to convert this specifier to that.\n let absoluteSpecifier = resolve(dirname(sourceFile.name), specifier);\n let packageRelativeSpecifier = explicitRelative(pkg.root, absoluteSpecifier);\n if (isExplicitlyExternal(packageRelativeSpecifier, pkg)) {\n let publicSpecifier = absoluteSpecifier.replace(pkg.root, pkg.name);\n return makeExternal(publicSpecifier, sourceFile, opts);\n } else {\n return specifier;\n }\n }\n\n // absolute package imports can also be explicitly external based on their\n // full specifier name\n if (isExplicitlyExternal(specifier, pkg)) {\n return makeExternal(specifier, sourceFile, opts);\n }\n\n let relocatedPkg = sourceFile.relocatedIntoPackage();\n if (relocatedPkg) {\n // this file has been moved into another package (presumably the app).\n\n // self-imports are legal in the app tree, even for v2 packages\n if (packageName === pkg.name) {\n return specifier;\n }\n\n // first try to resolve from the destination package\n if (isResolvable(packageName, relocatedPkg)) {\n if (!pkg.meta['auto-upgraded']) {\n throw new Error(\n `${pkg.name} is trying to import ${packageName} from within its app tree. This is unsafe, because ${pkg.name} can't control which dependencies are resolvable from the app`\n );\n }\n return specifier;\n } else {\n // second try to resolve from the source package\n let targetPkg = isResolvable(packageName, pkg);\n if (targetPkg) {\n if (!pkg.meta['auto-upgraded']) {\n throw new Error(\n `${pkg.name} is trying to import ${packageName} from within its app tree. This is unsafe, because ${pkg.name} can't control which dependencies are resolvable from the app`\n );\n }\n // we found it, but we need to rewrite it because it's not really going to\n // resolve from where its sitting\n return explicitRelative(dirname(sourceFile.name), specifier.replace(packageName, targetPkg.root));\n }\n }\n } else {\n if (isResolvable(packageName, pkg)) {\n if (!pkg.meta['auto-upgraded'] && !reliablyResolvable(pkg, packageName)) {\n throw new Error(\n `${pkg.name} is trying to import from ${packageName} but that is not one of its explicit dependencies`\n );\n }\n return specifier;\n }\n }\n\n // auto-upgraded packages can fall back to the set of known active addons\n if (pkg.meta['auto-upgraded'] && opts.activeAddons[packageName]) {\n return explicitRelative(dirname(sourceFile.name), specifier.replace(packageName, opts.activeAddons[packageName]));\n }\n\n // auto-upgraded packages can fall back to attmpeting to find dependencies at\n // runtime. Native v2 packages can only get this behavior in the\n // isExplicitlyExternal case above because they need to explicitly ask for\n // externals.\n if (pkg.meta['auto-upgraded']) {\n return makeExternal(specifier, sourceFile, opts);\n }\n\n if (pkg.isV2Ember()) {\n // native v2 packages don't automatically externalize *everything* the way\n // auto-upgraded packages do, but they still externalize known and approved\n // ember virtual packages (like @ember/component)\n if (emberVirtualPackages.has(packageName)) {\n return makeExternal(specifier, sourceFile, opts);\n }\n\n // native v2 packages don't automatically get to use every other addon as a\n // peerDep, but they do get the known and approved ember virtual peer deps,\n // like @glimmer/component\n if (emberVirtualPeerDeps.has(packageName)) {\n if (!opts.activeAddons[packageName]) {\n throw new Error(\n `${pkg.name} is trying to import from ${packageName}, which is supposed to be present in all ember apps but seems to be missing`\n );\n }\n return explicitRelative(dirname(sourceFile.name), specifier.replace(packageName, opts.activeAddons[packageName]));\n }\n }\n\n // non-resolvable imports in dynamic positions become runtime errors, not\n // build-time errors, so we emit the runtime error module here before the\n // stage3 packager has a chance to see the missing module. (Maybe some stage3\n // packagers will have this behavior by default, because it would make sense,\n // but webpack at least does not.)\n if (isDynamic) {\n return makeMissingModule(specifier, sourceFile, opts);\n }\n\n // this is falling through with the original specifier which was\n // non-resolvable, which will presumably cause a static build error in stage3.\n return specifier;\n}\n\nfunction makeMissingModule(specifier: string, sourceFile: AdjustFile, opts: Options): string {\n let target = join(opts.externalsDir, specifier + '.js');\n outputFileSync(\n target,\n dynamicMissingModule({\n moduleName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile.name), target.slice(0, -3));\n}\n\nfunction makeExternal(specifier: string, sourceFile: AdjustFile, opts: Options): string {\n let target = join(opts.externalsDir, specifier + '.js');\n outputFileSync(\n target,\n externalTemplate({\n runtimeName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile.name), target.slice(0, -3));\n}\n\nexport default function main(babel: typeof Babel) {\n let t = babel.types;\n return {\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n let opts = ensureOpts(state);\n state.adjustFile = new AdjustFile(path.hub.file.opts.filename, opts.relocatedFiles);\n addExtraImports(t, path, opts.extraImports);\n },\n exit(path: NodePath<t.Program>, state: State) {\n for (let child of path.get('body')) {\n if (child.isImportDeclaration() || child.isExportNamedDeclaration() || child.isExportAllDeclaration()) {\n rewriteTopLevelImport(t, child, state);\n }\n }\n },\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State) {\n if (isImportSyncExpression(t, path) || isDynamicImportExpression(t, path)) {\n const [source] = path.get('arguments');\n let opts = ensureOpts(state);\n let specifier = adjustSpecifier((source.node as any).value, state.adjustFile, opts, true);\n source.replaceWith(t.stringLiteral(specifier));\n return;\n }\n\n // Should/can we make this early exit when the first define was found?\n if (!isDefineExpression(t, path)) {\n return;\n }\n\n let pkg = state.adjustFile.owningPackage();\n if (pkg && pkg.isV2Ember() && !pkg.meta['auto-upgraded']) {\n throw new Error(\n `The file ${state.adjustFile.originalFile} in package ${pkg.name} tried to use AMD define. Native V2 Ember addons are forbidden from using AMD define, they must use ECMA export only.`\n );\n }\n\n let opts = ensureOpts(state);\n\n const dependencies = path.node.arguments[1];\n\n const specifiers = dependencies.elements.slice();\n specifiers.push(path.node.arguments[0]);\n\n for (let source of specifiers) {\n if (!source) {\n continue;\n }\n\n if (source.type !== 'StringLiteral') {\n throw path.buildCodeFrameError(`expected only string literal arguments`);\n }\n\n if (source.value === 'exports' || source.value === 'require') {\n // skip \"special\" AMD dependencies\n continue;\n }\n\n let specifier = adjustSpecifier(source.value, state.adjustFile, opts, false);\n\n if (specifier !== source.value) {\n source.value = specifier;\n }\n }\n },\n },\n };\n}\n\nfunction rewriteTopLevelImport(\n t: BabelTypes,\n path: NodePath<t.ImportDeclaration | t.ExportNamedDeclaration | t.ExportAllDeclaration>,\n state: State\n) {\n let opts = ensureOpts(state);\n const { source } = path.node;\n if (source === null || source === undefined) {\n return;\n }\n\n if (opts.emberNeedsModulesPolyfill && path.isImportDeclaration()) {\n let replacement = handleImportDeclaration(t, path);\n if (replacement) {\n path.replaceWith(replacement);\n return;\n }\n }\n\n let specifier = adjustSpecifier(source.value, state.adjustFile, opts, false);\n if (specifier !== source.value) {\n source.value = specifier;\n }\n}\n\n(main as any).baseDir = function () {\n return join(__dirname, '..');\n};\n\nfunction addExtraImports(t: BabelTypes, path: NodePath<t.Program>, extraImports: Required<Options>['extraImports']) {\n let counter = 0;\n for (let { absPath, target, runtimeName } of extraImports) {\n if (absPath === path.hub.file.opts.filename) {\n if (runtimeName) {\n path.node.body.unshift(amdDefine(t, runtimeName, counter));\n path.node.body.unshift(\n t.importDeclaration([t.importNamespaceSpecifier(t.identifier(`a${counter++}`))], t.stringLiteral(target))\n );\n } else {\n path.node.body.unshift(t.importDeclaration([], t.stringLiteral(target)));\n }\n }\n }\n}\n\nfunction amdDefine(t: BabelTypes, runtimeName: string, importCounter: number) {\n return t.expressionStatement(\n t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [\n t.stringLiteral(runtimeName),\n t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),\n ])\n );\n}\n\nclass AdjustFile {\n readonly originalFile: string;\n\n constructor(public name: string, relocatedFiles: Options['relocatedFiles']) {\n if (!name) {\n throw new Error(`bug: adjust-imports plugin was run without a filename`);\n }\n this.originalFile = relocatedFiles[name] || name;\n }\n\n get isRelocated() {\n return this.originalFile !== this.name;\n }\n\n @Memoize()\n owningPackage(): Package | undefined {\n return packageCache.ownerOfFile(this.originalFile);\n }\n\n @Memoize()\n relocatedIntoPackage(): Package | undefined {\n if (this.isRelocated) {\n return packageCache.ownerOfFile(this.name);\n }\n }\n}\n\nfunction ensureOpts(state: State): Options {\n let { opts } = state;\n if ('adjustImportsOptionsPath' in opts) {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n return (state.opts = { ...require(opts.adjustImportsOptionsPath), ...require(opts.relocatedFilesPath) });\n }\n return opts;\n}\n\n// we don't want to allow things that resolve only by accident that are likely\n// to break in other setups. For example: import your dependencies'\n// dependencies, or importing your own name from within a monorepo (which will\n// work because of the symlinking) without setting up \"exports\" (which makes\n// your own name reliably resolvable)\nfunction reliablyResolvable(pkg: V2Package, packageName: string) {\n if (pkg.hasDependency(packageName)) {\n return true;\n }\n\n if (pkg.name === packageName && pkg.packageJSON.exports) {\n return true;\n }\n\n if (emberVirtualPeerDeps.has(packageName)) {\n return true;\n }\n\n return false;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { NodeTemplateCompilerParams } from './template-compiler-node';
2
+ import { precompile } from './babel-plugin-inline-hbs-deps';
3
+ export interface Params {
4
+ templateCompiler: NodeTemplateCompilerParams;
5
+ }
6
+ declare const _default: {
7
+ (babel: typeof import("@babel/core")): unknown;
8
+ _parallelBabel: {
9
+ requireFile: string;
10
+ };
11
+ baseDir(): string;
12
+ };
13
+ export default _default;
14
+ export { precompile };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.precompile = void 0;
23
+ const template_compiler_node_1 = require("./template-compiler-node");
24
+ const babel_plugin_inline_hbs_deps_1 = __importStar(require("./babel-plugin-inline-hbs-deps"));
25
+ Object.defineProperty(exports, "precompile", { enumerable: true, get: function () { return babel_plugin_inline_hbs_deps_1.precompile; } });
26
+ exports.default = (0, babel_plugin_inline_hbs_deps_1.default)((opts) => new template_compiler_node_1.NodeTemplateCompiler(opts.templateCompiler));
27
+ //# sourceMappingURL=babel-plugin-inline-hbs-deps-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-inline-hbs-deps-node.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-deps-node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,qEAA4F;AAC5F,+FAAkE;AAOzD,2FAPM,yCAAU,OAON;AADnB,kBAAe,IAAA,sCAAI,EAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC","sourcesContent":["import { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';\nimport make, { precompile } from './babel-plugin-inline-hbs-deps';\n\nexport interface Params {\n templateCompiler: NodeTemplateCompilerParams;\n}\n\nexport default make((opts: Params) => new NodeTemplateCompiler(opts.templateCompiler));\nexport { precompile };\n"]}
@@ -0,0 +1,10 @@
1
+ import type * as Babel from '@babel/core';
2
+ import { TemplateCompiler } from './template-compiler-common';
3
+ export declare function precompile(templateSource: string, options: Record<string, unknown>): string;
4
+ export default function make(getCompiler: (opts: any) => TemplateCompiler): {
5
+ (babel: typeof Babel): unknown;
6
+ _parallelBabel: {
7
+ requireFile: string;
8
+ };
9
+ baseDir(): string;
10
+ };
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.precompile = void 0;
4
+ const path_1 = require("path");
5
+ const shared_internals_1 = require("@embroider/shared-internals");
6
+ const babel_import_util_1 = require("babel-import-util");
7
+ /*
8
+ In order to coordinate with babel-plugin-htmlbars-inline-precompile, we need
9
+ to give it a `precompile` function that, as a side-effect, captures the
10
+ dependencies needed within the current file. We do this coordination via this
11
+ module-scoped variable, which is safe given Javascript's single-threaded
12
+ nature and babel's synchronicity.
13
+ */
14
+ let currentState;
15
+ /*
16
+ This is the precompile function you should pass to
17
+ babel-plugin-htmlbars-inline-precompile.
18
+ */
19
+ function precompile(templateSource, options) {
20
+ if (!currentState) {
21
+ throw new Error(`bug: babel-plugin-htmlbars-inline-precompile and babel-plugin-inline-hbs-deps aren't coordinating correctly`);
22
+ }
23
+ let { compiled, dependencies } = compiler(currentState).precompile(templateSource, Object.assign({ filename: currentState.file.opts.filename }, options));
24
+ for (let dep of dependencies) {
25
+ currentState.dependencies.set(dep.runtimeName, dep);
26
+ }
27
+ return compiled;
28
+ }
29
+ exports.precompile = precompile;
30
+ function make(getCompiler) {
31
+ function inlineHBSTransform(babel) {
32
+ let t = babel.types;
33
+ return {
34
+ visitor: {
35
+ Program: {
36
+ enter(path, state) {
37
+ state.dependencies = new Map();
38
+ state.adder = new babel_import_util_1.ImportUtil(t, path);
39
+ state.emittedCallExpressions = new Set();
40
+ state.getCompiler = getCompiler;
41
+ currentState = state;
42
+ },
43
+ exit(path, state) {
44
+ // we are responsible for rewriting all usages of all the
45
+ // templateCompilationModules to standardize on
46
+ // @ember/template-compilation, so all imports other than that one
47
+ // need to be cleaned up here.
48
+ for (let moduleConfig of shared_internals_1.templateCompilationModules) {
49
+ if (moduleConfig.module !== '@ember/template-compilation') {
50
+ state.adder.removeImport(moduleConfig.module, moduleConfig.exportedName);
51
+ }
52
+ }
53
+ let counter = 0;
54
+ for (let dep of state.dependencies.values()) {
55
+ path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));
56
+ path.node.body.unshift(t.importDeclaration([t.importDefaultSpecifier(t.identifier(`a${counter++}`))], t.stringLiteral(dep.path)));
57
+ }
58
+ currentState = undefined;
59
+ },
60
+ },
61
+ TaggedTemplateExpression(path, state) {
62
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
63
+ if (path.get('tag').referencesImport(module, exportedName)) {
64
+ handleTagged(path, state, t);
65
+ }
66
+ }
67
+ },
68
+ CallExpression(path, state) {
69
+ if (state.emittedCallExpressions.has(path.node)) {
70
+ return;
71
+ }
72
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
73
+ if (path.get('callee').referencesImport(module, exportedName)) {
74
+ handleCalled(path, state, t);
75
+ }
76
+ }
77
+ },
78
+ },
79
+ };
80
+ }
81
+ inlineHBSTransform._parallelBabel = {
82
+ requireFile: __filename,
83
+ };
84
+ inlineHBSTransform.baseDir = function () {
85
+ return (0, path_1.join)(__dirname, '..');
86
+ };
87
+ function handleTagged(path, state, t) {
88
+ if (path.node.quasi.expressions.length) {
89
+ throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');
90
+ }
91
+ let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');
92
+ let newCallExpression = t.callExpression(state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'), [
93
+ t.stringLiteral(template),
94
+ // TODO: here is where we will put scope once ember support that
95
+ ]);
96
+ state.emittedCallExpressions.add(newCallExpression);
97
+ path.replaceWith(newCallExpression);
98
+ }
99
+ function handleCalled(path, state, t) {
100
+ let newCallExpression = t.callExpression(state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'), path.node.arguments);
101
+ state.emittedCallExpressions.add(newCallExpression);
102
+ path.replaceWith(newCallExpression);
103
+ }
104
+ function amdDefine(runtimeName, importCounter, t) {
105
+ return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [
106
+ t.stringLiteral(runtimeName),
107
+ t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),
108
+ ]));
109
+ }
110
+ return inlineHBSTransform;
111
+ }
112
+ exports.default = make;
113
+ function compiler(state) {
114
+ if (!state.templateCompiler) {
115
+ state.templateCompiler = state.getCompiler(state.opts);
116
+ }
117
+ return state.templateCompiler;
118
+ }
119
+ //# sourceMappingURL=babel-plugin-inline-hbs-deps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-inline-hbs-deps.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-deps.ts"],"names":[],"mappings":";;;AAGA,+BAA4B;AAG5B,kEAAyE;AACzE,yDAA+C;AAE/C;;;;;;EAME;AACF,IAAI,YAA+B,CAAC;AAEpC;;;EAGE;AACF,SAAgB,UAAU,CAAC,cAAsB,EAAE,OAAgC;IACjF,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CACb,6GAA6G,CAC9G,CAAC;KACH;IACD,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,cAAc,kBAC/E,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,IACtC,OAAO,EACV,CAAC;IACH,KAAK,IAAI,GAAG,IAAI,YAAY,EAAE;QAC5B,YAAY,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;KACrD;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAdD,gCAcC;AAiBD,SAAwB,IAAI,CAAC,WAA4C;IACvE,SAAS,kBAAkB,CAAC,KAAmB;QAC7C,IAAI,CAAC,GAAG,KAAK,CAAC,KA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ACH,CAAC;IACJ,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AApGD,uBAoGC;AAED,SAAS,QAAQ,CAAC,KAAY;IAC5B,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;QAC3B,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACxD;IACD,OAAO,KAAK,CAAC,gBAAgB,CAAC;AAChC,CAAC","sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { join } from 'path';\nimport { TemplateCompiler } from './template-compiler-common';\nimport { ResolvedDep } from './resolver';\nimport { templateCompilationModules } from '@embroider/shared-internals';\nimport { ImportUtil } from 'babel-import-util';\n\n/*\n In order to coordinate with babel-plugin-htmlbars-inline-precompile, we need\n to give it a `precompile` function that, as a side-effect, captures the\n dependencies needed within the current file. We do this coordination via this\n module-scoped variable, which is safe given Javascript's single-threaded\n nature and babel's synchronicity.\n*/\nlet currentState: State | undefined;\n\n/*\n This is the precompile function you should pass to\n babel-plugin-htmlbars-inline-precompile.\n*/\nexport function precompile(templateSource: string, options: Record<string, unknown>) {\n if (!currentState) {\n throw new Error(\n `bug: babel-plugin-htmlbars-inline-precompile and babel-plugin-inline-hbs-deps aren't coordinating correctly`\n );\n }\n let { compiled, dependencies } = compiler(currentState).precompile(templateSource, {\n filename: currentState.file.opts.filename,\n ...options,\n });\n for (let dep of dependencies) {\n currentState.dependencies.set(dep.runtimeName, dep);\n }\n return compiled;\n}\n\ninterface State {\n opts: {};\n file: {\n code: string;\n opts: {\n filename: string;\n };\n };\n dependencies: Map<string, ResolvedDep>;\n getCompiler: (opts: any) => TemplateCompiler;\n templateCompiler: TemplateCompiler | undefined;\n adder: ImportUtil;\n emittedCallExpressions: Set<t.Node>;\n}\n\nexport default function make(getCompiler: (opts: any) => TemplateCompiler) {\n function inlineHBSTransform(babel: typeof Babel): unknown {\n let t = babel.types;\n return {\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>, state: State) {\n state.dependencies = new Map();\n state.adder = new ImportUtil(t, path);\n state.emittedCallExpressions = new Set();\n state.getCompiler = getCompiler;\n currentState = state;\n },\n exit(path: NodePath<t.Program>, state: State) {\n // we are responsible for rewriting all usages of all the\n // templateCompilationModules to standardize on\n // @ember/template-compilation, so all imports other than that one\n // need to be cleaned up here.\n for (let moduleConfig of templateCompilationModules) {\n if (moduleConfig.module !== '@ember/template-compilation') {\n state.adder.removeImport(moduleConfig.module, moduleConfig.exportedName);\n }\n }\n let counter = 0;\n for (let dep of state.dependencies.values()) {\n path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));\n path.node.body.unshift(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(`a${counter++}`))],\n t.stringLiteral(dep.path)\n )\n );\n }\n currentState = undefined;\n },\n },\n TaggedTemplateExpression(path: NodePath<t.TaggedTemplateExpression>, state: State) {\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('tag').referencesImport(module, exportedName)) {\n handleTagged(path, state, t);\n }\n }\n },\n CallExpression(path: NodePath<t.CallExpression>, state: State) {\n if (state.emittedCallExpressions.has(path.node)) {\n return;\n }\n for (let { module, exportedName } of templateCompilationModules) {\n if (path.get('callee').referencesImport(module, exportedName)) {\n handleCalled(path, state, t);\n }\n }\n },\n },\n };\n }\n\n inlineHBSTransform._parallelBabel = {\n requireFile: __filename,\n };\n\n inlineHBSTransform.baseDir = function () {\n return join(__dirname, '..');\n };\n\n function handleTagged(path: NodePath<t.TaggedTemplateExpression>, state: State, t: typeof Babel.types) {\n if (path.node.quasi.expressions.length) {\n throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');\n }\n let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');\n let newCallExpression = t.callExpression(\n state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'),\n [\n t.stringLiteral(template),\n // TODO: here is where we will put scope once ember support that\n ]\n );\n\n state.emittedCallExpressions.add(newCallExpression);\n path.replaceWith(newCallExpression);\n }\n\n function handleCalled(path: NodePath<t.CallExpression>, state: State, t: typeof Babel.types) {\n let newCallExpression = t.callExpression(\n state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'),\n path.node.arguments\n );\n state.emittedCallExpressions.add(newCallExpression);\n path.replaceWith(newCallExpression);\n }\n\n function amdDefine(runtimeName: string, importCounter: number, t: typeof Babel.types) {\n return t.expressionStatement(\n t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [\n t.stringLiteral(runtimeName),\n t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),\n ])\n );\n }\n return inlineHBSTransform;\n}\n\nfunction compiler(state: State) {\n if (!state.templateCompiler) {\n state.templateCompiler = state.getCompiler(state.opts);\n }\n return state.templateCompiler;\n}\n"]}
@@ -1,13 +1,7 @@
1
1
  import { NodeTemplateCompilerParams } from './template-compiler-node';
2
- import { Params as CoreParams } from './babel-plugin-inline-hbs';
3
- export interface Params extends CoreParams {
2
+ import type * as Babel from '@babel/core';
3
+ export interface Params {
4
4
  templateCompiler: NodeTemplateCompilerParams;
5
5
  }
6
- declare const _default: {
7
- (babel: unknown): unknown;
8
- _parallelBabel: {
9
- requireFile: string;
10
- };
11
- baseDir(): string;
12
- };
6
+ declare const _default: (babel: typeof Babel) => Babel.PluginObj<unknown>;
13
7
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"babel-plugin-inline-hbs-node.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-node.ts"],"names":[],"mappings":";;;;;AAAA,qEAA4F;AAC5F,wFAAuE;AAMvE,kBAAe,IAAA,iCAAI,EAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC","sourcesContent":["import { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';\nimport make, { Params as CoreParams } from './babel-plugin-inline-hbs';\n\nexport interface Params extends CoreParams {\n templateCompiler: NodeTemplateCompilerParams;\n}\n\nexport default make((opts: Params) => new NodeTemplateCompiler(opts.templateCompiler));\n"]}
1
+ {"version":3,"file":"babel-plugin-inline-hbs-node.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-node.ts"],"names":[],"mappings":";;;;;AAAA,qEAA4F;AAC5F,wFAA6C;AAO7C,kBAAe,IAAA,iCAAI,EAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAExD,CAAC","sourcesContent":["import { NodeTemplateCompiler, NodeTemplateCompilerParams } from './template-compiler-node';\nimport make from './babel-plugin-inline-hbs';\nimport type * as Babel from '@babel/core';\n\nexport interface Params {\n templateCompiler: NodeTemplateCompilerParams;\n}\n\nexport default make((opts: Params) => new NodeTemplateCompiler(opts.templateCompiler)) as (\n babel: typeof Babel\n) => babel.PluginObj<unknown>;\n"]}
@@ -1,10 +1,9 @@
1
+ import type * as Babel from '@babel/core';
1
2
  import { TemplateCompiler } from './template-compiler-common';
2
3
  import { ResolvedDep } from './resolver';
3
4
  import { ImportUtil } from 'babel-import-util';
4
- interface State {
5
- opts: {
6
- stage: 1 | 3;
7
- };
5
+ interface State<O> {
6
+ opts: O;
8
7
  file: {
9
8
  code: string;
10
9
  opts: {
@@ -15,9 +14,8 @@ interface State {
15
14
  templateCompiler: TemplateCompiler | undefined;
16
15
  adder: ImportUtil;
17
16
  }
18
- export declare type Params = State['opts'];
19
- export default function make(getCompiler: (opts: any) => TemplateCompiler): {
20
- (babel: unknown): unknown;
17
+ export default function make<O>(getCompiler: (opts: O) => TemplateCompiler): {
18
+ (babel: typeof Babel): Babel.PluginObj<State<O>>;
21
19
  _parallelBabel: {
22
20
  requireFile: string;
23
21
  };
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
+ /*
3
+ This plugin is used only for Ember < 3.27. For newer Ember's we have a
4
+ different implementation that shares the standard
5
+ babel-plugin-htmlbars-inline-precompile and supports passing Javascript
6
+ lexically scoped names into templates.
7
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  const path_1 = require("path");
4
10
  const core_1 = require("@babel/core");
5
11
  const babel_import_util_1 = require("babel-import-util");
6
- // These are the known names that people are using to import the `hbs` macro
7
- // from. In theory the original plugin lets people customize these names, but
8
- // that is a terrible idea.
9
- const modulePaths = [
10
- ['htmlbars-inline-precompile', 'default'],
11
- ['ember-cli-htmlbars-inline-precompile', 'default'],
12
- ['ember-cli-htmlbars', 'hbs'],
13
- ];
12
+ const shared_internals_1 = require("@embroider/shared-internals");
14
13
  function make(getCompiler) {
15
14
  function inlineHBSTransform(babel) {
16
15
  let t = babel.types;
@@ -22,8 +21,8 @@ function make(getCompiler) {
22
21
  state.adder = new babel_import_util_1.ImportUtil(t, path);
23
22
  },
24
23
  exit(path, state) {
25
- if (state.opts.stage === 3) {
26
- pruneImports(path);
24
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
25
+ state.adder.removeImport(module, exportedName);
27
26
  }
28
27
  let counter = 0;
29
28
  for (let dep of state.dependencies.values()) {
@@ -33,15 +32,15 @@ function make(getCompiler) {
33
32
  },
34
33
  },
35
34
  TaggedTemplateExpression(path, state) {
36
- for (let [modulePath, identifier] of modulePaths) {
37
- if (path.get('tag').referencesImport(modulePath, identifier)) {
35
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
36
+ if (path.get('tag').referencesImport(module, exportedName)) {
38
37
  handleTagged(path, state, t);
39
38
  }
40
39
  }
41
40
  },
42
41
  CallExpression(path, state) {
43
- for (let [modulePath, identifier] of modulePaths) {
44
- if (path.get('callee').referencesImport(modulePath, identifier)) {
42
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
43
+ if (path.get('callee').referencesImport(module, exportedName)) {
45
44
  handleCalled(path, state, t);
46
45
  }
47
46
  }
@@ -60,74 +59,37 @@ function make(getCompiler) {
60
59
  throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');
61
60
  }
62
61
  let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');
63
- if (state.opts.stage === 1) {
64
- let compiled = compiler(state).applyTransforms(state.file.opts.filename, template);
65
- path.get('quasi').replaceWith(t.templateLiteral([t.templateElement({ raw: compiled, cooked: compiled })], []));
66
- }
67
- else {
68
- let { compiled, dependencies } = compiler(state).precompile(state.file.opts.filename, template);
69
- for (let dep of dependencies) {
70
- state.dependencies.set(dep.runtimeName, dep);
71
- }
72
- path.replaceWith(t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [
73
- jsonLiteral(compiled, t),
74
- ]));
62
+ let { compiled, dependencies } = compiler(state).precompile(template, { filename: state.file.opts.filename });
63
+ for (let dep of dependencies) {
64
+ state.dependencies.set(dep.runtimeName, dep);
75
65
  }
66
+ path.replaceWith(t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [
67
+ jsonLiteral(compiled, t),
68
+ ]));
76
69
  }
77
70
  function handleCalled(path, state, t) {
78
71
  let { template, insertRuntimeErrors } = getCallArguments(path);
79
72
  let compilerInstance = compiler(state);
80
- if (state.opts.stage === 1) {
81
- let compiled;
82
- try {
83
- compiled = compilerInstance.applyTransforms(state.file.opts.filename, template);
84
- }
85
- catch (err) {
86
- if (insertRuntimeErrors) {
87
- // in stage 1 we just leave the bad template in place (we were only
88
- // trying to run transforms and re-emit hbs), so that it will be handled
89
- // at stage3 instead.
90
- return;
91
- }
92
- throw err;
93
- }
94
- path.get('arguments')[0].replaceWith(t.stringLiteral(compiled));
73
+ let result;
74
+ try {
75
+ result = compilerInstance.precompile(template, { filename: state.file.opts.filename, insertRuntimeErrors });
95
76
  }
96
- else {
97
- let result;
98
- try {
99
- result = compilerInstance.precompile(state.file.opts.filename, template);
100
- }
101
- catch (err) {
102
- if (insertRuntimeErrors) {
103
- path.replaceWith(t.callExpression(t.functionExpression(null, [], t.blockStatement([
104
- t.throwStatement(t.newExpression(t.identifier('Error'), [t.stringLiteral(err.message)])),
105
- ])), []));
106
- return;
107
- }
108
- throw err;
77
+ catch (err) {
78
+ if (insertRuntimeErrors) {
79
+ path.replaceWith(t.callExpression(t.functionExpression(null, [], t.blockStatement([
80
+ t.throwStatement(t.newExpression(t.identifier('Error'), [t.stringLiteral(err.message)])),
81
+ ])), []));
82
+ return;
109
83
  }
110
- let { compiled, dependencies } = result;
111
- for (let dep of dependencies) {
112
- state.dependencies.set(dep.runtimeName, dep);
113
- }
114
- path.replaceWith(t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [
115
- jsonLiteral(compiled, t),
116
- ]));
84
+ throw err;
117
85
  }
118
- }
119
- function pruneImports(path) {
120
- if (!path.isProgram()) {
121
- return;
122
- }
123
- for (let topLevelPath of path.get('body')) {
124
- if (topLevelPath.isImportDeclaration()) {
125
- let modulePath = topLevelPath.get('source').node.value;
126
- if (modulePaths.find(p => p[0] === modulePath)) {
127
- topLevelPath.remove();
128
- }
129
- }
86
+ let { compiled, dependencies } = result;
87
+ for (let dep of dependencies) {
88
+ state.dependencies.set(dep.runtimeName, dep);
130
89
  }
90
+ path.replaceWith(t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [
91
+ jsonLiteral(compiled, t),
92
+ ]));
131
93
  }
132
94
  function jsonLiteral(value, t) {
133
95
  if (typeof value === 'undefined') {