@embroider/core 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. package/package.json +1 -1
  2. package/src/babel-plugin-adjust-imports.d.ts +3 -34
  3. package/src/babel-plugin-adjust-imports.js +94 -318
  4. package/src/babel-plugin-adjust-imports.js.map +1 -1
  5. package/src/babel-plugin-inline-hbs-deps-node.d.ts +14 -0
  6. package/src/babel-plugin-inline-hbs-deps-node.js +27 -0
  7. package/src/babel-plugin-inline-hbs-deps-node.js.map +1 -0
  8. package/src/babel-plugin-inline-hbs-deps.d.ts +10 -0
  9. package/src/babel-plugin-inline-hbs-deps.js +134 -0
  10. package/src/babel-plugin-inline-hbs-deps.js.map +1 -0
  11. package/src/babel-plugin-inline-hbs-node.d.ts +7 -0
  12. package/src/babel-plugin-inline-hbs-node.js +15 -0
  13. package/src/babel-plugin-inline-hbs-node.js.map +1 -0
  14. package/src/babel-plugin-inline-hbs.d.ts +24 -0
  15. package/src/babel-plugin-inline-hbs.js +142 -0
  16. package/src/babel-plugin-inline-hbs.js.map +1 -0
  17. package/src/babel-plugin-stage1-inline-hbs-node.d.ts +12 -0
  18. package/src/babel-plugin-stage1-inline-hbs-node.js +9 -0
  19. package/src/babel-plugin-stage1-inline-hbs-node.js.map +1 -0
  20. package/src/babel-plugin-stage1-inline-hbs.d.ts +9 -0
  21. package/src/babel-plugin-stage1-inline-hbs.js +96 -0
  22. package/src/babel-plugin-stage1-inline-hbs.js.map +1 -0
  23. package/src/browser-index.d.ts +1 -0
  24. package/src/browser-index.js +6 -0
  25. package/src/browser-index.js.map +1 -0
  26. package/src/ember-template-compiler-types.d.ts +41 -0
  27. package/src/ember-template-compiler-types.js +3 -0
  28. package/src/ember-template-compiler-types.js.map +1 -0
  29. package/src/load-ember-template-compiler.d.ts +6 -0
  30. package/src/load-ember-template-compiler.js +57 -0
  31. package/src/load-ember-template-compiler.js.map +1 -0
  32. package/src/messages.d.ts +0 -1
  33. package/src/mini-modules-polyfill.d.ts +12 -0
  34. package/src/mini-modules-polyfill.js +80 -0
  35. package/src/mini-modules-polyfill.js.map +1 -0
  36. package/src/module-resolver.d.ts +46 -0
  37. package/src/module-resolver.js +260 -0
  38. package/src/module-resolver.js.map +1 -0
  39. package/src/patch-template-compiler.d.ts +1 -0
  40. package/src/patch-template-compiler.js +176 -0
  41. package/src/patch-template-compiler.js.map +1 -0
  42. package/src/resolver-plugin.d.ts +3 -0
  43. package/src/resolver-plugin.js +53 -0
  44. package/src/resolver-plugin.js.map +1 -0
  45. package/src/resolver.d.ts +14 -0
  46. package/src/resolver.js +3 -0
  47. package/src/resolver.js.map +1 -0
  48. package/src/template-compiler-common.d.ts +70 -0
  49. package/src/template-compiler-common.js +176 -0
  50. package/src/template-compiler-common.js.map +1 -0
  51. package/src/template-compiler-node.d.ts +17 -0
  52. package/src/template-compiler-node.js +32 -0
  53. package/src/template-compiler-node.js.map +1 -0
@@ -1 +1 @@
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,2DAA6C;AAC7C,mDAA0C;AAC1C,yDAA+C;AAC/C,mCAAqC;AACrC,uCAAsE;AAyCtE,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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H,CAAC;CACF;AAdC;IADC,IAAA,4BAAO,GAAE;+CAGT;AAGD;IADC,IAAA,4BAAO,GAAE;sDAST;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,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,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 Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { PackageCache, Package, V2Package, explicitRelative } from '@embroider/shared-internals';\nimport { Memoize } from 'typescript-memoize';\nimport { compile } from './js-handlebars';\nimport { ImportUtil } from 'babel-import-util';\nimport { randomBytes } from 'crypto';\nimport { outputFileSync, pathExistsSync, renameSync } from 'fs-extra';\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 appRoot: string;\n}\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: V2Package, appRoot: string): false | Package {\n try {\n let dep = PackageCache.shared('embroider-stage3', appRoot).resolve(packageName, fromPkg);\n if (!dep.isEmberPackage() && fromPkg.meta['auto-upgraded'] && !fromPkg.hasDependency('ember-auto-import')) {\n // classic ember addons can only import non-ember dependencies if they\n // have ember-auto-import.\n //\n // whereas native v2 packages can always import any dependency\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 if (!pkg.meta['auto-upgraded'] && emberVirtualPeerDeps.has(packageName)) {\n // Native v2 addons are allowed to use the emberVirtualPeerDeps like\n // `@glimmer/component`. And like all v2 addons, it's important that they\n // see those dependencies after those dependencies have been converted to\n // v2.\n //\n // But unlike auto-upgraded addons, native v2 addons are not necessarily\n // copied out of their original place in node_modules. And from that\n // original place they might accidentally resolve the emberVirtualPeerDeps\n // that are present there in v1 format.\n //\n // So before we even check isResolvable, we adjust these imports to point at\n // the app's copies instead.\n if (emberVirtualPeerDeps.has(packageName)) {\n if (!opts.activeAddons[packageName]) {\n throw new Error(`${pkg.name} is trying to import the app's ${packageName} package, but it seems to be missing`);\n }\n return explicitRelative(dirname(sourceFile.name), specifier.replace(packageName, opts.activeAddons[packageName]));\n }\n }\n\n let relocatedPkg = sourceFile.relocatedIntoPackage();\n if (relocatedPkg) {\n // this file has been moved into another package (presumably the app).\n\n // first try to resolve from the destination package\n if (isResolvable(packageName, relocatedPkg, opts.appRoot)) {\n // self-imports are legal in the app tree, even for v2 packages.\n if (!pkg.meta['auto-upgraded'] && packageName !== pkg.name) {\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, opts.appRoot);\n if (targetPkg) {\n // self-imports are legal in the app tree, even for v2 packages.\n if (!pkg.meta['auto-upgraded'] && packageName !== pkg.name) {\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, opts.appRoot)) {\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 //\n // v2 packages can fall back to the set of known active addons only to find\n // themselves (which is needed due to app tree merging)\n if ((pkg.meta['auto-upgraded'] || packageName === pkg.name) && opts.activeAddons[packageName]) {\n return explicitRelative(dirname(sourceFile.name), specifier.replace(packageName, opts.activeAddons[packageName]));\n }\n\n if (pkg.meta['auto-upgraded']) {\n // auto-upgraded packages can fall back to attempting 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 return makeExternal(specifier, sourceFile, opts);\n } else {\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\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, 'missing', specifier + '.js');\n atomicWrite(\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 atomicWrite(\n target,\n externalTemplate({\n runtimeName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile.name), target.slice(0, -3));\n}\n\nfunction atomicWrite(path: string, content: string) {\n if (pathExistsSync(path)) {\n return;\n }\n let suffix = randomBytes(8).toString('hex');\n outputFileSync(path + suffix, content);\n try {\n renameSync(path + suffix, path);\n } catch (err: any) {\n // windows throws EPERM for concurrent access. For us it's not an error\n // condition because the other thread is writing the exact same value we\n // would have.\n if (err.code !== 'EPERM') {\n throw err;\n }\n }\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, opts.appRoot);\n let adder = new ImportUtil(t, path);\n addExtraImports(adder, 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(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 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 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(\n adder: ImportUtil,\n t: BabelTypes,\n path: NodePath<t.Program>,\n extraImports: Required<Options>['extraImports']\n) {\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, adder, path, target, runtimeName));\n } else {\n adder.importForSideEffect(target);\n }\n }\n }\n}\n\nfunction amdDefine(t: BabelTypes, adder: ImportUtil, path: NodePath<t.Program>, target: string, runtimeName: string) {\n let value = t.callExpression(adder.import(path, '@embroider/macros', 'importSync'), [t.stringLiteral(target)]);\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(value)])),\n ])\n );\n}\n\nclass AdjustFile {\n readonly originalFile: string;\n private packageCache: PackageCache;\n\n constructor(public name: string, relocatedFiles: Options['relocatedFiles'], appRoot: string) {\n this.packageCache = PackageCache.shared('embroider-stage3', appRoot);\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 this.packageCache.ownerOfFile(this.originalFile);\n }\n\n @Memoize()\n relocatedIntoPackage(): V2Package | undefined {\n if (this.isRelocated) {\n let owning = this.packageCache.ownerOfFile(this.name);\n if (owning && !owning.isV2Ember()) {\n throw new Error(`bug: it should only be possible to get relocated into a v2 ember package here`);\n }\n return owning;\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,+BAAqC;AAIrC,yDAA+C;AAC/C,mCAAqC;AACrC,uCAAsE;AACtE,kEAA+D;AAC/D,mDAA0C;AAC1C,uDAAsD;AACtD,gEAAuC;AAsBvC,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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C,CAAC,CAAC;YAC9F,MAAM;QACR,KAAK,aAAa;YAChB,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC;YACpC,MAAM;QACR,KAAK,iBAAiB;YACpB,YAAY,GAAG,iBAAiB,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YACnG,MAAM;QACR;YACE,MAAM,IAAA,sBAAW,EAAC,UAAU,CAAC,CAAC;KACjC;IACD,IAAI,YAAY,EAAE;QAChB,MAAM,CAAC,YAAY,CAAC,CAAC;KACtB;AACH,CAAC","sourcesContent":["import { join, dirname } from 'path';\nimport type { NodePath } from '@babel/traverse';\nimport type * as Babel from '@babel/core';\nimport type { types as t } from '@babel/core';\nimport { ImportUtil } from 'babel-import-util';\nimport { randomBytes } from 'crypto';\nimport { outputFileSync, pathExistsSync, renameSync } from 'fs-extra';\nimport { explicitRelative } from '@embroider/shared-internals';\nimport { compile } from './js-handlebars';\nimport { Options, Resolver } from './module-resolver';\nimport assertNever from 'assert-never';\n\ninterface State {\n resolver: Resolver;\n opts: Options | DeflatedOptions;\n}\n\nexport { Options };\n\nexport interface DeflatedOptions {\n adjustImportsOptionsPath: string;\n relocatedFilesPath: string;\n}\n\ntype BabelTypes = typeof t;\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\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.resolver = new Resolver(path.hub.file.opts.filename, opts);\n let adder = new ImportUtil(t, path);\n addExtraImports(adder, 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(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 resolve((source.node as any).value, true, state, newSpecifier => {\n source.replaceWith(t.stringLiteral(newSpecifier));\n });\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.resolver.owningPackage();\n if (pkg && pkg.isV2Ember() && !pkg.meta['auto-upgraded']) {\n throw new Error(\n `The file ${state.resolver.originalFilename} 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 const dependencies = path.node.arguments[1];\n\n const specifiers = dependencies.elements.slice();\n specifiers.push(path.node.arguments[0]);\n\n for (const 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 resolve(source.value, false, state, newSpecifier => {\n source.value = newSpecifier;\n });\n }\n },\n },\n };\n}\n\nfunction rewriteTopLevelImport(\n path: NodePath<t.ImportDeclaration | t.ExportNamedDeclaration | t.ExportAllDeclaration>,\n state: State\n) {\n const { source } = path.node;\n if (source === null || source === undefined) {\n return;\n }\n\n resolve(source.value, false, state, newSpecifier => {\n source.value = newSpecifier;\n });\n}\n\n(main as any).baseDir = function () {\n return join(__dirname, '..');\n};\n\nfunction addExtraImports(\n adder: ImportUtil,\n t: BabelTypes,\n path: NodePath<t.Program>,\n extraImports: Required<Options>['extraImports']\n) {\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, adder, path, target, runtimeName));\n } else {\n adder.importForSideEffect(target);\n }\n }\n }\n}\n\nfunction amdDefine(t: BabelTypes, adder: ImportUtil, path: NodePath<t.Program>, target: string, runtimeName: string) {\n let value = t.callExpression(adder.import(path, '@embroider/macros', 'importSync'), [t.stringLiteral(target)]);\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(value)])),\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\nfunction makeExternal(specifier: string, sourceFile: string, opts: Options): string {\n let target = join(opts.externalsDir, specifier + '.js');\n atomicWrite(\n target,\n externalTemplate({\n runtimeName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile), target.slice(0, -3));\n}\n\nfunction atomicWrite(path: string, content: string) {\n if (pathExistsSync(path)) {\n return;\n }\n let suffix = randomBytes(8).toString('hex');\n outputFileSync(path + suffix, content);\n try {\n renameSync(path + suffix, path);\n } catch (err: any) {\n // windows throws EPERM for concurrent access. For us it's not an error\n // condition because the other thread is writing the exact same value we\n // would have.\n if (err.code !== 'EPERM') {\n throw err;\n }\n }\n}\n\nfunction makeMissingModule(specifier: string, sourceFile: string, opts: Options): string {\n let target = join(opts.externalsDir, 'missing', specifier + '.js');\n atomicWrite(\n target,\n dynamicMissingModule({\n moduleName: specifier,\n })\n );\n return explicitRelative(dirname(sourceFile), target.slice(0, -3));\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 resolve(specifier: string, isDynamic: boolean, state: State, setter: (specifier: string) => void) {\n let resolution = state.resolver.resolve(specifier, isDynamic);\n let newSpecifier: string | undefined;\n switch (resolution.result) {\n case 'continue':\n return;\n case 'external':\n newSpecifier = makeExternal(resolution.specifier, state.resolver.filename, ensureOpts(state));\n break;\n case 'redirect-to':\n newSpecifier = resolution.specifier;\n break;\n case 'runtime-failure':\n newSpecifier = makeMissingModule(resolution.specifier, state.resolver.filename, ensureOpts(state));\n break;\n default:\n throw assertNever(resolution);\n }\n if (newSpecifier) {\n setter(newSpecifier);\n }\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 type { 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,134 @@
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-ember-template-compilation, 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-ember-template-compilation.
18
+ */
19
+ function precompile(templateSource, options) {
20
+ if (!currentState) {
21
+ throw new Error(`bug: babel-plugin-ember-template-compilation and babel-plugin-inline-hbs-deps aren't coordinating correctly`);
22
+ }
23
+ let { compiled, dependencies } = compiler(currentState).precompile(templateSource, {
24
+ filename: currentState.file.opts.filename,
25
+ ...options,
26
+ });
27
+ for (let dep of dependencies) {
28
+ currentState.dependencies.set(dep.runtimeName, dep);
29
+ }
30
+ return compiled;
31
+ }
32
+ exports.precompile = precompile;
33
+ function make(getCompiler) {
34
+ function inlineHBSTransform(babel) {
35
+ let t = babel.types;
36
+ return {
37
+ visitor: {
38
+ Program: {
39
+ enter(path, state) {
40
+ state.dependencies = new Map();
41
+ state.adder = new babel_import_util_1.ImportUtil(t, path);
42
+ state.emittedCallExpressions = new Set();
43
+ state.getCompiler = getCompiler;
44
+ currentState = state;
45
+ },
46
+ exit(path, state) {
47
+ // we are responsible for rewriting all usages of all the
48
+ // templateCompilationModules to standardize on
49
+ // @ember/template-compilation, so all imports other than that one
50
+ // need to be cleaned up here.
51
+ for (let moduleConfig of shared_internals_1.templateCompilationModules) {
52
+ if (moduleConfig.module !== '@ember/template-compilation') {
53
+ state.adder.removeImport(moduleConfig.module, moduleConfig.exportedName);
54
+ }
55
+ }
56
+ let counter = 0;
57
+ for (let dep of state.dependencies.values()) {
58
+ path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));
59
+ path.node.body.unshift(t.importDeclaration([t.importDefaultSpecifier(t.identifier(`a${counter++}`))], t.stringLiteral(dep.path)));
60
+ }
61
+ currentState = undefined;
62
+ },
63
+ },
64
+ TaggedTemplateExpression(path, state) {
65
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
66
+ if (path.get('tag').referencesImport(module, exportedName)) {
67
+ handleTagged(path, state, t);
68
+ }
69
+ }
70
+ },
71
+ CallExpression(path, state) {
72
+ if (state.emittedCallExpressions.has(path.node)) {
73
+ return;
74
+ }
75
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
76
+ if (path.get('callee').referencesImport(module, exportedName)) {
77
+ handleCalled(path, state, t);
78
+ }
79
+ }
80
+ },
81
+ },
82
+ };
83
+ }
84
+ inlineHBSTransform._parallelBabel = {
85
+ requireFile: __filename,
86
+ };
87
+ inlineHBSTransform.baseDir = function () {
88
+ return (0, path_1.join)(__dirname, '..');
89
+ };
90
+ function handleTagged(path, state, t) {
91
+ if (path.node.quasi.expressions.length) {
92
+ throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');
93
+ }
94
+ let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');
95
+ let args = [t.stringLiteral(template)];
96
+ let locals = [
97
+ // TODO: this is where lexically scoped dependencies go
98
+ ];
99
+ let opts = precompileOpts(locals, t);
100
+ if (opts) {
101
+ args.push(opts);
102
+ }
103
+ let newCallExpression = t.callExpression(state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'), args);
104
+ state.emittedCallExpressions.add(newCallExpression);
105
+ path.replaceWith(newCallExpression);
106
+ }
107
+ function handleCalled(path, state, t) {
108
+ let newCallExpression = t.callExpression(state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'), path.node.arguments);
109
+ state.emittedCallExpressions.add(newCallExpression);
110
+ path.replaceWith(newCallExpression);
111
+ }
112
+ function precompileOpts(locals, t) {
113
+ if (locals.length > 0) {
114
+ return t.objectExpression([
115
+ t.objectProperty(t.identifier('scope'), t.arrowFunctionExpression([], t.objectExpression(locals.map(name => t.objectProperty(name, name, false, true))))),
116
+ ]);
117
+ }
118
+ }
119
+ function amdDefine(runtimeName, importCounter, t) {
120
+ return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [
121
+ t.stringLiteral(runtimeName),
122
+ t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),
123
+ ]));
124
+ }
125
+ return inlineHBSTransform;
126
+ }
127
+ exports.default = make;
128
+ function compiler(state) {
129
+ if (!state.templateCompiler) {
130
+ state.templateCompiler = state.getCompiler(state.opts);
131
+ }
132
+ return state.templateCompiler;
133
+ }
134
+ //# sourceMappingURL=babel-plugin-inline-hbs-deps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-inline-h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a,CAAC,WAAW,CAAC;YAC5B,CAAC,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SACzG,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAzHD,uBAyHC;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 type { 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-ember-template-compilation, 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-ember-template-compilation.\n*/\nexport function precompile(templateSource: string, options: Record<string, unknown>) {\n if (!currentState) {\n throw new Error(\n `bug: babel-plugin-ember-template-compilation 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 args: t.Expression[] = [t.stringLiteral(template)];\n\n let locals: t.Identifier[] = [\n // TODO: this is where lexically scoped dependencies go\n ];\n let opts = precompileOpts(locals, t);\n if (opts) {\n args.push(opts);\n }\n\n let newCallExpression = t.callExpression(\n state.adder.import(path, '@ember/template-compilation', 'precompileTemplate'),\n args\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 precompileOpts(locals: t.Identifier[], t: typeof Babel.types) {\n if (locals.length > 0) {\n return t.objectExpression([\n t.objectProperty(\n t.identifier('scope'),\n t.arrowFunctionExpression(\n [],\n t.objectExpression(locals.map(name => t.objectProperty(name, name, false, true)))\n )\n ),\n ]);\n }\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"]}
@@ -0,0 +1,7 @@
1
+ import { NodeTemplateCompilerParams } from './template-compiler-node';
2
+ import type * as Babel from '@babel/core';
3
+ export interface Params {
4
+ templateCompiler: NodeTemplateCompilerParams;
5
+ }
6
+ declare const _default: (babel: typeof Babel) => Babel.PluginObj<unknown>;
7
+ export default _default;
@@ -0,0 +1,15 @@
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-ember-template-compilation and supports passing Javascript
6
+ lexically scoped names into templates.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const template_compiler_node_1 = require("./template-compiler-node");
13
+ const babel_plugin_inline_hbs_1 = __importDefault(require("./babel-plugin-inline-hbs"));
14
+ exports.default = (0, babel_plugin_inline_hbs_1.default)((opts) => new template_compiler_node_1.NodeTemplateCompiler(opts.templateCompiler));
15
+ //# sourceMappingURL=babel-plugin-inline-hbs-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-inline-hbs-node.js","sourceRoot":"","sources":["babel-plugin-inline-hbs-node.ts"],"names":[],"mappings":";AAAA;;;;;EAKE;;;;;AAEF,qEAA4F;AAC5F,wFAA6C;AAO7C,kBAAe,IAAA,iCAAI,EAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,6CAAoB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAExD,CAAC","sourcesContent":["/*\n This plugin is used only for Ember < 3.27. For newer Ember's we have a\n different implementation that shares the standard\n babel-plugin-ember-template-compilation and supports passing Javascript\n lexically scoped names into templates.\n*/\n\nimport { 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"]}
@@ -0,0 +1,24 @@
1
+ import type * as Babel from '@babel/core';
2
+ import type { TemplateCompiler } from './template-compiler-common';
3
+ import { ResolvedDep } from './resolver';
4
+ import { ImportUtil } from 'babel-import-util';
5
+ interface State<O> {
6
+ opts: O;
7
+ file: {
8
+ code: string;
9
+ opts: {
10
+ filename: string;
11
+ };
12
+ };
13
+ dependencies: Map<string, ResolvedDep>;
14
+ templateCompiler: TemplateCompiler | undefined;
15
+ adder: ImportUtil;
16
+ }
17
+ export default function make<O>(getCompiler: (opts: O) => TemplateCompiler): {
18
+ (babel: typeof Babel): Babel.PluginObj<State<O>>;
19
+ _parallelBabel: {
20
+ requireFile: string;
21
+ };
22
+ baseDir(): string;
23
+ };
24
+ export {};
@@ -0,0 +1,142 @@
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-ember-template-compilation and supports passing Javascript
6
+ lexically scoped names into templates.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const path_1 = require("path");
10
+ const core_1 = require("@babel/core");
11
+ const babel_import_util_1 = require("babel-import-util");
12
+ const shared_internals_1 = require("@embroider/shared-internals");
13
+ function make(getCompiler) {
14
+ function inlineHBSTransform(babel) {
15
+ let t = babel.types;
16
+ return {
17
+ visitor: {
18
+ Program: {
19
+ enter(path, state) {
20
+ state.dependencies = new Map();
21
+ state.adder = new babel_import_util_1.ImportUtil(t, path);
22
+ },
23
+ exit(path, state) {
24
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
25
+ state.adder.removeImport(module, exportedName);
26
+ }
27
+ let counter = 0;
28
+ for (let dep of state.dependencies.values()) {
29
+ path.node.body.unshift(amdDefine(dep.runtimeName, counter, t));
30
+ path.node.body.unshift(t.importDeclaration([t.importDefaultSpecifier(t.identifier(`a${counter++}`))], t.stringLiteral(dep.path)));
31
+ }
32
+ },
33
+ },
34
+ TaggedTemplateExpression(path, state) {
35
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
36
+ if (path.get('tag').referencesImport(module, exportedName)) {
37
+ handleTagged(path, state, t);
38
+ }
39
+ }
40
+ },
41
+ CallExpression(path, state) {
42
+ for (let { module, exportedName } of shared_internals_1.templateCompilationModules) {
43
+ if (path.get('callee').referencesImport(module, exportedName)) {
44
+ handleCalled(path, state, t);
45
+ }
46
+ }
47
+ },
48
+ },
49
+ };
50
+ }
51
+ inlineHBSTransform._parallelBabel = {
52
+ requireFile: __filename,
53
+ };
54
+ inlineHBSTransform.baseDir = function () {
55
+ return (0, path_1.join)(__dirname, '..');
56
+ };
57
+ function handleTagged(path, state, t) {
58
+ if (path.node.quasi.expressions.length) {
59
+ throw path.buildCodeFrameError('placeholders inside a tagged template string are not supported');
60
+ }
61
+ let template = path.node.quasi.quasis.map(quasi => quasi.value.cooked).join('');
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);
65
+ }
66
+ path.replaceWith(t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [
67
+ jsonLiteral(compiled, t),
68
+ ]));
69
+ }
70
+ function handleCalled(path, state, t) {
71
+ let { template, insertRuntimeErrors } = getCallArguments(path);
72
+ let compilerInstance = compiler(state);
73
+ let result;
74
+ try {
75
+ result = compilerInstance.precompile(template, { filename: state.file.opts.filename, insertRuntimeErrors });
76
+ }
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;
83
+ }
84
+ throw err;
85
+ }
86
+ let { compiled, dependencies } = result;
87
+ for (let dep of dependencies) {
88
+ state.dependencies.set(dep.runtimeName, dep);
89
+ }
90
+ path.replaceWith(t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [
91
+ jsonLiteral(compiled, t),
92
+ ]));
93
+ }
94
+ function jsonLiteral(value, t) {
95
+ if (typeof value === 'undefined') {
96
+ return t.identifier('undefined');
97
+ }
98
+ let ast = (0, core_1.parse)(`a(${value})`, {});
99
+ let statement = ast.program.body[0];
100
+ let expression = statement.expression;
101
+ return expression.arguments[0];
102
+ }
103
+ function compiler(state) {
104
+ if (!state.templateCompiler) {
105
+ state.templateCompiler = getCompiler(state.opts);
106
+ }
107
+ return state.templateCompiler;
108
+ }
109
+ function amdDefine(runtimeName, importCounter, t) {
110
+ return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('window'), t.identifier('define')), [
111
+ t.stringLiteral(runtimeName),
112
+ t.functionExpression(null, [], t.blockStatement([t.returnStatement(t.identifier(`a${importCounter}`))])),
113
+ ]));
114
+ }
115
+ function getTemplateString(template, path) {
116
+ if ((template === null || template === void 0 ? void 0 : template.type) === 'StringLiteral') {
117
+ return template.value;
118
+ }
119
+ // treat inert TemplateLiteral (without subexpressions) like a StringLiteral
120
+ if ((template === null || template === void 0 ? void 0 : template.type) === 'TemplateLiteral' && !template.expressions.length) {
121
+ return template.quasis[0].value.cooked;
122
+ }
123
+ throw path.buildCodeFrameError('hbs accepts only a string literal argument');
124
+ }
125
+ function getCallArguments(path) {
126
+ let [template, options] = path.node.arguments;
127
+ let insertRuntimeErrors = (options === null || options === void 0 ? void 0 : options.type) === 'ObjectExpression' &&
128
+ options.properties.some(prop => prop.type === 'ObjectProperty' &&
129
+ prop.computed === false &&
130
+ prop.key.type === 'Identifier' &&
131
+ prop.key.name === 'insertRuntimeErrors' &&
132
+ prop.value.type === 'BooleanLiteral' &&
133
+ prop.value.value);
134
+ return {
135
+ template: getTemplateString(template, path),
136
+ insertRuntimeErrors,
137
+ };
138
+ }
139
+ return inlineHBSTransform;
140
+ }
141
+ exports.default = make;
142
+ //# sourceMappingURL=babel-plugin-inline-hbs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-inline-hbs.js","sourceRoot":"","sources":["babel-plugin-inline-hbs.ts"],"names":[],"mappings":";AAAA;;;;;EAKE;;AAKF,+BAA4B;AAE5B,sCAAoC;AAEpC,yDAA+C;AAC/C,kEAAyE;AAiBzE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AC;QAEJ,OAAO;YACL,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC;YAC3C,mBAAmB;SACpB,CAAC;IACJ,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AApKD,uBAoKC","sourcesContent":["/*\n This plugin is used only for Ember < 3.27. For newer Ember's we have a\n different implementation that shares the standard\n babel-plugin-ember-template-compilation and supports passing Javascript\n lexically scoped names into templates.\n*/\n\nimport type { types as t } from '@babel/core';\nimport type * as Babel from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport { join } from 'path';\nimport type { TemplateCompiler } from './template-compiler-common';\nimport { parse } from '@babel/core';\nimport { ResolvedDep } from './resolver';\nimport { ImportUtil } from 'babel-import-util';\nimport { templateCompilationModules } from '@embroider/shared-internals';\n\ntype BabelTypes = typeof t;\n\ninterface State<O> {\n opts: O;\n file: {\n code: string;\n opts: {\n filename: string;\n };\n };\n dependencies: Map<string, ResolvedDep>;\n templateCompiler: TemplateCompiler | undefined;\n adder: ImportUtil;\n}\n\nexport default function make<O>(getCompiler: (opts: O) => TemplateCompiler) {\n function inlineHBSTransform(babel: typeof Babel): Babel.PluginObj<State<O>> {\n let t = babel.types;\n return {\n visitor: {\n Program: {\n enter(path: NodePath<t.Program>, state: State<O>) {\n state.dependencies = new Map();\n state.adder = new ImportUtil(t, path);\n },\n exit(path: NodePath<t.Program>, state: State<O>) {\n for (let { module, exportedName } of templateCompilationModules) {\n state.adder.removeImport(module, exportedName);\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 },\n },\n TaggedTemplateExpression(path: NodePath<t.TaggedTemplateExpression>, state: State<O>) {\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<O>) {\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<O>, t: BabelTypes) {\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 { compiled, dependencies } = compiler(state).precompile(template, { filename: state.file.opts.filename });\n for (let dep of dependencies) {\n state.dependencies.set(dep.runtimeName, dep);\n }\n\n path.replaceWith(\n t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [\n jsonLiteral(compiled, t),\n ])\n );\n }\n\n function handleCalled(path: NodePath<t.CallExpression>, state: State<O>, t: BabelTypes) {\n let { template, insertRuntimeErrors } = getCallArguments(path);\n let compilerInstance = compiler(state);\n\n let result: ReturnType<TemplateCompiler['precompile']>;\n try {\n result = compilerInstance.precompile(template, { filename: state.file.opts.filename, insertRuntimeErrors });\n } catch (err) {\n if (insertRuntimeErrors) {\n path.replaceWith(\n t.callExpression(\n t.functionExpression(\n null,\n [],\n t.blockStatement([\n t.throwStatement(t.newExpression(t.identifier('Error'), [t.stringLiteral(err.message)])),\n ])\n ),\n []\n )\n );\n return;\n }\n throw err;\n }\n let { compiled, dependencies } = result;\n for (let dep of dependencies) {\n state.dependencies.set(dep.runtimeName, dep);\n }\n path.replaceWith(\n t.callExpression(state.adder.import(path, '@ember/template-factory', 'createTemplateFactory'), [\n jsonLiteral(compiled, t),\n ])\n );\n }\n\n function jsonLiteral(value: unknown | undefined, t: BabelTypes) {\n if (typeof value === 'undefined') {\n return t.identifier('undefined');\n }\n let ast = parse(`a(${value})`, {}) as t.File;\n let statement = ast.program.body[0] as t.ExpressionStatement;\n let expression = statement.expression as t.CallExpression;\n return expression.arguments[0];\n }\n\n function compiler(state: State<O>) {\n if (!state.templateCompiler) {\n state.templateCompiler = getCompiler(state.opts);\n }\n return state.templateCompiler;\n }\n\n function amdDefine(runtimeName: string, importCounter: number, t: BabelTypes) {\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\n function getTemplateString(template: any, path: NodePath<t.CallExpression>): string {\n if (template?.type === 'StringLiteral') {\n return template.value;\n }\n // treat inert TemplateLiteral (without subexpressions) like a StringLiteral\n if (template?.type === 'TemplateLiteral' && !template.expressions.length) {\n return template.quasis[0].value.cooked;\n }\n throw path.buildCodeFrameError('hbs accepts only a string literal argument');\n }\n\n function getCallArguments(path: NodePath<t.CallExpression>): { template: string; insertRuntimeErrors: boolean } {\n let [template, options] = path.node.arguments;\n\n let insertRuntimeErrors =\n options?.type === 'ObjectExpression' &&\n options.properties.some(\n prop =>\n prop.type === 'ObjectProperty' &&\n prop.computed === false &&\n prop.key.type === 'Identifier' &&\n prop.key.name === 'insertRuntimeErrors' &&\n prop.value.type === 'BooleanLiteral' &&\n prop.value.value\n );\n\n return {\n template: getTemplateString(template, path),\n insertRuntimeErrors,\n };\n }\n\n return inlineHBSTransform;\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { NodeTemplateCompilerParams } from './template-compiler-node';
2
+ export interface Params {
3
+ templateCompiler: NodeTemplateCompilerParams;
4
+ }
5
+ declare const _default: {
6
+ (babel: typeof import("@babel/core")): unknown;
7
+ _parallelBabel: {
8
+ requireFile: string;
9
+ };
10
+ baseDir(): string;
11
+ };
12
+ export default _default;
@@ -0,0 +1,9 @@
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
+ const template_compiler_node_1 = require("./template-compiler-node");
7
+ const babel_plugin_stage1_inline_hbs_1 = __importDefault(require("./babel-plugin-stage1-inline-hbs"));
8
+ exports.default = (0, babel_plugin_stage1_inline_hbs_1.default)((opts) => new template_compiler_node_1.NodeTemplateCompiler(opts.templateCompiler));
9
+ //# sourceMappingURL=babel-plugin-stage1-inline-hbs-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-plugin-stage1-inline-hbs-node.js","sourceRoot":"","sources":["babel-plugin-stage1-inline-hbs-node.ts"],"names":[],"mappings":";;;;;AAAA,qEAA4F;AAC5F,sGAAoD;AAMpD,kBAAe,IAAA,wCAAI,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 from './babel-plugin-stage1-inline-hbs';\n\nexport interface Params {\n templateCompiler: NodeTemplateCompilerParams;\n}\n\nexport default make((opts: Params) => new NodeTemplateCompiler(opts.templateCompiler));\n"]}
@@ -0,0 +1,9 @@
1
+ import type { TemplateCompiler } from './template-compiler-common';
2
+ import type * as Babel from '@babel/core';
3
+ export default function make<Opts>(getCompiler: (opts: Opts) => TemplateCompiler): {
4
+ (babel: typeof Babel): unknown;
5
+ _parallelBabel: {
6
+ requireFile: string;
7
+ };
8
+ baseDir(): string;
9
+ };