@embroider/core 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embroider/core",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "private": false,
5
5
  "description": "A build system for EmberJS applications.",
6
6
  "repository": {
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "./src/messages": "./src/messages.js",
20
20
  "./src/babel-plugin-inline-hbs": "./src/babel-plugin-inline-hbs.js",
21
+ "./src/babel-plugin-stage1-inline-hbs": "./src/babel-plugin-stage1-inline-hbs.js",
21
22
  "./src/mini-modules-polyfill": "./src/mini-modules-polyfill.js",
22
23
  "./src/load-ember-template-compiler": "./src/load-ember-template-compiler.js"
23
24
  },
@@ -37,8 +38,8 @@
37
38
  "@babel/plugin-transform-runtime": "^7.14.5",
38
39
  "@babel/runtime": "^7.14.5",
39
40
  "@babel/traverse": "^7.14.5",
40
- "@embroider/macros": "1.7.0",
41
- "@embroider/shared-internals": "1.7.0",
41
+ "@embroider/macros": "1.8.1",
42
+ "@embroider/shared-internals": "1.8.1",
42
43
  "assert-never": "^1.2.1",
43
44
  "babel-import-util": "^1.1.0",
44
45
  "babel-plugin-ember-template-compilation": "^1.0.0",
@@ -82,35 +82,53 @@ class HTMLEntrypoint {
82
82
  let matchingBundles = match.get(firstVariant);
83
83
  let matchingFastbootBundles = fastbootVariant >= 0 ? match.get(fastbootVariant) || [] : [];
84
84
  for (let placeholder of placeholders) {
85
+ placeholder.clear();
85
86
  if (supportsFastboot && placeholder.isScript()) {
86
87
  // if there is any fastboot involved, we will emit the lazy bundles
87
88
  // right before our first script.
88
89
  let lazyMatch = stats.lazyBundles.get(src);
89
90
  if (lazyMatch && !insertedLazy.has(src)) {
90
- insertLazyJavascript(lazyMatch, placeholder, this.publicAssetURL);
91
+ insertLazyJavascript(lazyMatch, placeholder, this.rootURL);
91
92
  insertLazyStyles(lazyMatch, placeholder, this.publicAssetURL);
92
93
  insertedLazy.add(src);
93
94
  }
94
95
  }
95
96
  for (let [base, fastboot] of (0, zip_1.default)(matchingBundles, matchingFastbootBundles)) {
97
+ if (supportsFastboot) {
98
+ // the fastboot version gets prefixed with the rootURL, which
99
+ // points to our local build directory, because that's where
100
+ // fastboot always loads scripts from. If there's no
101
+ // fastboot-specific variant, fastboot loads the base variant, but
102
+ // still from rootURL rather than publicAssetURL.
103
+ fastboot = this.rootURL + (fastboot !== null && fastboot !== void 0 ? fastboot : base);
104
+ }
105
+ if (base) {
106
+ // the browser version gets prefixed with the publicAssetURL
107
+ // because that's where browsers will load it from
108
+ base = this.publicAssetURL + base;
109
+ }
96
110
  if (!base) {
97
111
  // this bundle only exists in the fastboot variant
98
112
  let element = placeholder.start.ownerDocument.createElement('fastboot-script');
99
- element.setAttribute('src', this.publicAssetURL + fastboot);
113
+ element.setAttribute('src', fastboot);
100
114
  placeholder.insert(element);
101
115
  placeholder.insertNewline();
102
116
  }
103
- else if (!fastboot || base === fastboot) {
104
- // no specialized fastboot variant
105
- let src = this.publicAssetURL + base;
106
- placeholder.insertURL(src);
117
+ else if (!fastboot) {
118
+ // no fastboot variant
119
+ placeholder.insertURL(base);
120
+ }
121
+ else if (fastboot === base) {
122
+ // fastboot variant happens to be exactly the same bundle as base
123
+ // (and publicAssetURL===rootURL), so a plain script tag covers
124
+ // both
125
+ placeholder.insertURL(base);
107
126
  }
108
127
  else {
109
128
  // we have both and they differ
110
- let src = this.publicAssetURL + base;
111
- let element = placeholder.insertURL(src);
129
+ let element = placeholder.insertURL(base);
112
130
  if (element) {
113
- element.setAttribute('data-fastboot-src', this.publicAssetURL + fastboot);
131
+ element.setAttribute('data-fastboot-src', fastboot);
114
132
  }
115
133
  }
116
134
  }
@@ -134,11 +152,15 @@ function isAbsoluteURL(url) {
134
152
  }
135
153
  // we (somewhat arbitrarily) decide to put the lazy javascript bundles before
136
154
  // the very first <script> that we have rewritten
137
- function insertLazyJavascript(lazyBundles, placeholder, publicAssetURL) {
155
+ function insertLazyJavascript(lazyBundles, placeholder, rootURL) {
138
156
  for (let bundle of lazyBundles) {
139
157
  if (bundle.endsWith('.js')) {
140
158
  let element = placeholder.start.ownerDocument.createElement('fastboot-script');
141
- element.setAttribute('src', publicAssetURL + bundle);
159
+ // we're using rootURL instead of publicAssetURL here because
160
+ // <fastboot-script> is executed by fastboot, which always loads them from
161
+ // the local build directory. NOT from the publicAssetURL that browsers
162
+ // will use, which could be a CDN.
163
+ element.setAttribute('src', rootURL + bundle);
142
164
  placeholder.insert(element);
143
165
  placeholder.insertNewline();
144
166
  }
@@ -1 +1 @@
1
- {"version":3,"file":"html-entrypoint.js","sourceRoot":"","sources":["html-entrypoint.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA0D;AAC1D,uCAAwC;AACxC,+BAA4B;AAC5B,iCAA8B;AAC9B,iEAAyC;AACzC,qDAA6B;AAC7B,0EAA6C;AAG7C,MAAa,cAAc;IAOzB,YACU,gBAAwB,EACxB,OAAe,EACf,cAAsB,EACvB,QAAgB;QAHf,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,YAAO,GAAP,OAAO,CAAQ;QACf,mBAAc,GAAd,cAAc,CAAQ;QACvB,aAAQ,GAAR,QAAQ,CAAQ;QATjB,iBAAY,GAA+B,IAAI,GAAG,EAAE,CAAC;QAC7D,YAAO,GAAa,EAAE,CAAC;QACvB,YAAO,GAAa,EAAE,CAAC;QACvB,WAAM,GAAa,EAAE,CAAC;QAQpB,IAAI,CAAC,GAAG,GAAG,IAAI,aAAK,CAAC,IAAA,uBAAY,EAAC,IAAA,WAAI,EAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAEvF,KAAK,IAAI,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE;YACpC,IAAI,QAAQ,GAAG,GAAsB,CAAC;YACtC,IAAI,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C,GAAG,CAAC,CAAC;AACxC,CAAC;AAED,6EAA6E;AAC7E,iDAAiD;AACjD,SAAS,oBAAoB,CAAC,WAAqB,EAAE,WAAwB,EAAE,cAAsB;IACnG,KAAK,IAAI,MAAM,IAAI,WAAW,EAAE;QAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC1B,IAAI,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;YAC/E,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAAC,CAAC;YACrD,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,WAAW,CAAC,aAAa,EAAE,CAAC;SAC7B;KACF;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,WAAqB,EAAE,WAAwB,EAAE,cAAsB;IAC/F,KAAK,IAAI,MAAM,IAAI,WAAW,EAAE;QAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAC3B,IAAI,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACpE,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC,CAAC;YACtD,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAC1C,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,WAAW,CAAC,aAAa,EAAE,CAAC;SAC7B;KACF;AACH,CAAC","sourcesContent":["import { getOrCreate } from '@embroider/shared-internals';\nimport { readFileSync } from 'fs-extra';\nimport { join } from 'path';\nimport { JSDOM } from 'jsdom';\nimport partition from 'lodash/partition';\nimport zip from 'lodash/zip';\nimport Placeholder from './html-placeholder';\nimport { Variant } from './packager';\n\nexport class HTMLEntrypoint {\n private dom: JSDOM;\n private placeholders: Map<string, Placeholder[]> = new Map();\n modules: string[] = [];\n scripts: string[] = [];\n styles: string[] = [];\n\n constructor(\n private pathToVanillaApp: string,\n private rootURL: string,\n private publicAssetURL: string,\n public filename: string\n ) {\n this.dom = new JSDOM(readFileSync(join(this.pathToVanillaApp, this.filename), 'utf8'));\n\n for (let tag of this.handledStyles()) {\n let styleTag = tag as HTMLLinkElement;\n let href = styleTag.href;\n if (!isAbsoluteURL(href)) {\n let url = this.relativeToApp(href);\n this.styles.push(url);\n let placeholder = new Placeholder(styleTag);\n let list = getOrCreate(this.placeholders, url, () => []);\n list.push(placeholder);\n }\n }\n\n for (let scriptTag of this.handledScripts()) {\n // scriptTag.src include rootURL. Convert it to be relative to the app.\n let src = this.relativeToApp(scriptTag.src);\n\n if (scriptTag.type === 'module') {\n this.modules.push(src);\n } else {\n this.scripts.push(src);\n }\n\n let placeholder = new Placeholder(scriptTag);\n let list = getOrCreate(this.placeholders, src, () => []);\n list.push(placeholder);\n }\n }\n\n private relativeToApp(rootRelativeURL: string) {\n return rootRelativeURL.replace(this.rootURL, '');\n }\n\n private handledScripts() {\n let scriptTags = [...this.dom.window.document.querySelectorAll('script')] as HTMLScriptElement[];\n let [ignoredScriptTags, handledScriptTags] = partition(scriptTags, scriptTag => {\n return !scriptTag.src || scriptTag.hasAttribute('data-embroider-ignore') || isAbsoluteURL(scriptTag.src);\n });\n for (let scriptTag of ignoredScriptTags) {\n scriptTag.removeAttribute('data-embroider-ignore');\n }\n return handledScriptTags;\n }\n\n private handledStyles() {\n let styleTags = [...this.dom.window.document.querySelectorAll('link[rel=\"stylesheet\"]')] as HTMLLinkElement[];\n let [ignoredStyleTags, handledStyleTags] = partition(styleTags, styleTag => {\n return !styleTag.href || styleTag.hasAttribute('data-embroider-ignore') || isAbsoluteURL(styleTag.href);\n });\n for (let styleTag of ignoredStyleTags) {\n styleTag.removeAttribute('data-embroider-ignore');\n }\n return handledStyleTags;\n }\n\n // bundles maps from input asset to a per-variant map of output assets\n render(stats: BundleSummary): string {\n let insertedLazy = new Set<string>();\n let fastbootVariant = stats.variants.findIndex(v => Boolean(v.runtime === 'fastboot'));\n let supportsFastboot = stats.variants.some(v => v.runtime === 'fastboot' || v.runtime === 'all');\n\n for (let [src, placeholders] of this.placeholders) {\n let match = stats.entrypoints.get(src);\n if (match) {\n let firstVariant = stats.variants.findIndex((_, index) => Boolean(match!.get(index)));\n let matchingBundles = match.get(firstVariant)!;\n let matchingFastbootBundles = fastbootVariant >= 0 ? match.get(fastbootVariant) || [] : [];\n\n for (let placeholder of placeholders) {\n if (supportsFastboot && placeholder.isScript()) {\n // if there is any fastboot involved, we will emit the lazy bundles\n // right before our first script.\n\n let lazyMatch = stats.lazyBundles.get(src);\n if (lazyMatch && !insertedLazy.has(src)) {\n insertLazyJavascript(lazyMatch, placeholder, this.publicAssetURL);\n insertLazyStyles(lazyMatch, placeholder, this.publicAssetURL);\n insertedLazy.add(src);\n }\n }\n for (let [base, fastboot] of zip(matchingBundles, matchingFastbootBundles)) {\n if (!base) {\n // this bundle only exists in the fastboot variant\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n element.setAttribute('src', this.publicAssetURL + fastboot);\n placeholder.insert(element);\n placeholder.insertNewline();\n } else if (!fastboot || base === fastboot) {\n // no specialized fastboot variant\n let src = this.publicAssetURL + base;\n placeholder.insertURL(src);\n } else {\n // we have both and they differ\n let src = this.publicAssetURL + base;\n let element = placeholder.insertURL(src);\n if (element) {\n element.setAttribute('data-fastboot-src', this.publicAssetURL + fastboot);\n }\n }\n }\n }\n } else {\n // no match means keep the original HTML content for this placeholder.\n // (If we really wanted it empty instead, there would be matchingBundles\n // and it would be an empty list.)\n for (let placeholder of placeholders) {\n placeholder.reset();\n }\n }\n }\n return this.dom.serialize();\n }\n}\n\nexport interface BundleSummary {\n // entrypoints.get(inputAsset).get(variantIndex) === outputAssets\n //\n // these are the output assets that are needed eagerly to boot the given input\n // asset\n entrypoints: Map<string, Map<number, string[]>>;\n\n // lazyBundles.get(inputAsset) === lazyOutputAssets\n //\n // these are the output assets that might be loaded lazyily at runtime by the\n // given input asset.\n //\n // These are tracked specifically for the fastboot variant, because that's\n // where we need to be responsble for them.\n lazyBundles: Map<string, string[]>;\n\n variants: Variant[];\n}\n\nfunction isAbsoluteURL(url: string) {\n return /^(?:[a-z]+:)?\\/\\//i.test(url);\n}\n\n// we (somewhat arbitrarily) decide to put the lazy javascript bundles before\n// the very first <script> that we have rewritten\nfunction insertLazyJavascript(lazyBundles: string[], placeholder: Placeholder, publicAssetURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.js')) {\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n element.setAttribute('src', publicAssetURL + bundle);\n placeholder.insert(element);\n placeholder.insertNewline();\n }\n }\n}\n\nfunction insertLazyStyles(lazyBundles: string[], placeholder: Placeholder, publicAssetURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.css')) {\n let element = placeholder.start.ownerDocument.createElement('link');\n element.setAttribute('href', publicAssetURL + bundle);\n element.setAttribute('rel', 'stylesheet');\n placeholder.insert(element);\n placeholder.insertNewline();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"html-entrypoint.js","sourceRoot":"","sources":["html-entrypoint.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA0D;AAC1D,uCAAwC;AACxC,+BAA4B;AAC5B,iCAA8B;AAC9B,iEAAyC;AACzC,qDAA6B;AAC7B,0EAA6C;AAG7C,MAAa,cAAc;IAOzB,YACU,gBAAwB,EACxB,OAAe,EACf,cAAsB,EACvB,QAAgB;QAHf,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,YAAO,GAAP,OAAO,CAAQ;QACf,mBAAc,GAAd,cAAc,CAAQ;QACvB,aAAQ,GAAR,QAAQ,CAAQ;QATjB,iBAAY,GAA+B,IAAI,GAAG,EAAE,CAAC;QAC7D,YAAO,GAAa,EAAE,CAAC;QACvB,YAAO,GAAa,EAAE,CAAC;QACvB,WAAM,GAAa,EAAE,CAAC;QAQpB,IAAI,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IAAI,WAAW,EAAE;QAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAC3B,IAAI,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACpE,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC,CAAC;YACtD,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAC1C,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC5B,WAAW,CAAC,aAAa,EAAE,CAAC;SAC7B;KACF;AACH,CAAC","sourcesContent":["import { getOrCreate } from '@embroider/shared-internals';\nimport { readFileSync } from 'fs-extra';\nimport { join } from 'path';\nimport { JSDOM } from 'jsdom';\nimport partition from 'lodash/partition';\nimport zip from 'lodash/zip';\nimport Placeholder from './html-placeholder';\nimport { Variant } from './packager';\n\nexport class HTMLEntrypoint {\n private dom: JSDOM;\n private placeholders: Map<string, Placeholder[]> = new Map();\n modules: string[] = [];\n scripts: string[] = [];\n styles: string[] = [];\n\n constructor(\n private pathToVanillaApp: string,\n private rootURL: string,\n private publicAssetURL: string,\n public filename: string\n ) {\n this.dom = new JSDOM(readFileSync(join(this.pathToVanillaApp, this.filename), 'utf8'));\n\n for (let tag of this.handledStyles()) {\n let styleTag = tag as HTMLLinkElement;\n let href = styleTag.href;\n if (!isAbsoluteURL(href)) {\n let url = this.relativeToApp(href);\n this.styles.push(url);\n let placeholder = new Placeholder(styleTag);\n let list = getOrCreate(this.placeholders, url, () => []);\n list.push(placeholder);\n }\n }\n\n for (let scriptTag of this.handledScripts()) {\n // scriptTag.src include rootURL. Convert it to be relative to the app.\n let src = this.relativeToApp(scriptTag.src);\n\n if (scriptTag.type === 'module') {\n this.modules.push(src);\n } else {\n this.scripts.push(src);\n }\n\n let placeholder = new Placeholder(scriptTag);\n let list = getOrCreate(this.placeholders, src, () => []);\n list.push(placeholder);\n }\n }\n\n private relativeToApp(rootRelativeURL: string) {\n return rootRelativeURL.replace(this.rootURL, '');\n }\n\n private handledScripts() {\n let scriptTags = [...this.dom.window.document.querySelectorAll('script')] as HTMLScriptElement[];\n let [ignoredScriptTags, handledScriptTags] = partition(scriptTags, scriptTag => {\n return !scriptTag.src || scriptTag.hasAttribute('data-embroider-ignore') || isAbsoluteURL(scriptTag.src);\n });\n for (let scriptTag of ignoredScriptTags) {\n scriptTag.removeAttribute('data-embroider-ignore');\n }\n return handledScriptTags;\n }\n\n private handledStyles() {\n let styleTags = [...this.dom.window.document.querySelectorAll('link[rel=\"stylesheet\"]')] as HTMLLinkElement[];\n let [ignoredStyleTags, handledStyleTags] = partition(styleTags, styleTag => {\n return !styleTag.href || styleTag.hasAttribute('data-embroider-ignore') || isAbsoluteURL(styleTag.href);\n });\n for (let styleTag of ignoredStyleTags) {\n styleTag.removeAttribute('data-embroider-ignore');\n }\n return handledStyleTags;\n }\n\n // bundles maps from input asset to a per-variant map of output assets\n render(stats: BundleSummary): string {\n let insertedLazy = new Set<string>();\n let fastbootVariant = stats.variants.findIndex(v => Boolean(v.runtime === 'fastboot'));\n let supportsFastboot = stats.variants.some(v => v.runtime === 'fastboot' || v.runtime === 'all');\n\n for (let [src, placeholders] of this.placeholders) {\n let match = stats.entrypoints.get(src);\n if (match) {\n let firstVariant = stats.variants.findIndex((_, index) => Boolean(match!.get(index)));\n let matchingBundles = match.get(firstVariant)!;\n let matchingFastbootBundles = fastbootVariant >= 0 ? match.get(fastbootVariant) || [] : [];\n\n for (let placeholder of placeholders) {\n placeholder.clear();\n if (supportsFastboot && placeholder.isScript()) {\n // if there is any fastboot involved, we will emit the lazy bundles\n // right before our first script.\n\n let lazyMatch = stats.lazyBundles.get(src);\n if (lazyMatch && !insertedLazy.has(src)) {\n insertLazyJavascript(lazyMatch, placeholder, this.rootURL);\n insertLazyStyles(lazyMatch, placeholder, this.publicAssetURL);\n insertedLazy.add(src);\n }\n }\n for (let [base, fastboot] of zip(matchingBundles, matchingFastbootBundles)) {\n if (supportsFastboot) {\n // the fastboot version gets prefixed with the rootURL, which\n // points to our local build directory, because that's where\n // fastboot always loads scripts from. If there's no\n // fastboot-specific variant, fastboot loads the base variant, but\n // still from rootURL rather than publicAssetURL.\n fastboot = this.rootURL + (fastboot ?? base);\n }\n\n if (base) {\n // the browser version gets prefixed with the publicAssetURL\n // because that's where browsers will load it from\n base = this.publicAssetURL + base;\n }\n\n if (!base) {\n // this bundle only exists in the fastboot variant\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n element.setAttribute('src', fastboot!);\n placeholder.insert(element);\n placeholder.insertNewline();\n } else if (!fastboot) {\n // no fastboot variant\n placeholder.insertURL(base);\n } else if (fastboot === base) {\n // fastboot variant happens to be exactly the same bundle as base\n // (and publicAssetURL===rootURL), so a plain script tag covers\n // both\n placeholder.insertURL(base);\n } else {\n // we have both and they differ\n let element = placeholder.insertURL(base);\n if (element) {\n element.setAttribute('data-fastboot-src', fastboot);\n }\n }\n }\n }\n } else {\n // no match means keep the original HTML content for this placeholder.\n // (If we really wanted it empty instead, there would be matchingBundles\n // and it would be an empty list.)\n for (let placeholder of placeholders) {\n placeholder.reset();\n }\n }\n }\n return this.dom.serialize();\n }\n}\n\nexport interface BundleSummary {\n // entrypoints.get(inputAsset).get(variantIndex) === outputAssets\n //\n // these are the output assets that are needed eagerly to boot the given input\n // asset\n entrypoints: Map<string, Map<number, string[]>>;\n\n // lazyBundles.get(inputAsset) === lazyOutputAssets\n //\n // these are the output assets that might be loaded lazyily at runtime by the\n // given input asset.\n //\n // These are tracked specifically for the fastboot variant, because that's\n // where we need to be responsble for them.\n lazyBundles: Map<string, string[]>;\n\n variants: Variant[];\n}\n\nfunction isAbsoluteURL(url: string) {\n return /^(?:[a-z]+:)?\\/\\//i.test(url);\n}\n\n// we (somewhat arbitrarily) decide to put the lazy javascript bundles before\n// the very first <script> that we have rewritten\nfunction insertLazyJavascript(lazyBundles: string[], placeholder: Placeholder, rootURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.js')) {\n let element = placeholder.start.ownerDocument.createElement('fastboot-script');\n // we're using rootURL instead of publicAssetURL here because\n // <fastboot-script> is executed by fastboot, which always loads them from\n // the local build directory. NOT from the publicAssetURL that browsers\n // will use, which could be a CDN.\n element.setAttribute('src', rootURL + bundle);\n placeholder.insert(element);\n placeholder.insertNewline();\n }\n }\n}\n\nfunction insertLazyStyles(lazyBundles: string[], placeholder: Placeholder, publicAssetURL: string) {\n for (let bundle of lazyBundles) {\n if (bundle.endsWith('.css')) {\n let element = placeholder.start.ownerDocument.createElement('link');\n element.setAttribute('href', publicAssetURL + bundle);\n element.setAttribute('rel', 'stylesheet');\n placeholder.insert(element);\n placeholder.insertNewline();\n }\n }\n}\n"]}