Skip to content

Commit 8ae45fd

Browse files
DRY DRY DRY
1 parent c43f2a4 commit 8ae45fd

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

scripts/bundles/plugins/sizzle-plugin.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ export function sizzlePlugin(opts: BuildOptions): Plugin {
3232
if (id !== 'sizzle') {
3333
return null;
3434
}
35-
const f = opts.isProd ? 'sizzle.min.js' : 'sizzle.js';
36-
const sizzlePath = join(opts.nodeModulesDir, 'sizzle', 'dist', f);
37-
const sizzleContent = await fs.readFile(sizzlePath, 'utf8');
38-
return getSizzleBundle(opts, sizzleContent);
35+
return getSizzleBundle(opts);
3936
},
4037
};
4138
}
4239

4340
/**
4441
* Creates a sizzle bundle to inline
4542
* @param opts the options being used during a build of the Stencil compiler
46-
* @param content the sizzle source contents
4743
* @returns a modified version of sizzle, wrapped in an immediately invoked function expression (IIFE)
4844
*/
49-
function getSizzleBundle(opts: BuildOptions, content: string): string {
45+
async function getSizzleBundle(opts: BuildOptions): Promise<string> {
46+
const f = opts.isProd ? 'sizzle.min.js' : 'sizzle.js';
47+
const sizzlePath = join(opts.nodeModulesDir, 'sizzle', 'dist', f);
48+
const sizzleContent = await fs.readFile(sizzlePath, 'utf8');
49+
5050
return `// Sizzle ${opts.sizzleVersion}
5151
export default (function() {
5252
const window = {
@@ -63,18 +63,22 @@ const window = {
6363
};
6464
const module = { exports: {} };
6565
66-
${content}
66+
${sizzleContent}
6767
6868
return module.exports;
6969
})();
7070
`;
7171
}
7272

73+
/**
74+
* Write a file containing our patched version of Sizzle to a location on disk
75+
* and return the path for that location
76+
*
77+
* @param opts the build options
78+
* @returns a Promise wrapping the path where Sizzle can be found
79+
*/
7380
export async function writeSizzleBundle(opts: BuildOptions): Promise<string> {
74-
const f = opts.isProd ? 'sizzle.min.js' : 'sizzle.js';
75-
const sizzlePath = join(opts.nodeModulesDir, 'sizzle', 'dist', f);
76-
const sizzleContent = await fs.readFile(sizzlePath, 'utf8');
77-
const patchedSizzle = getSizzleBundle(opts, sizzleContent);
81+
const patchedSizzle = await getSizzleBundle(opts);
7882

7983
const fileName = `sizzle--bundle-cache${opts.isProd ? '.min' : ''}.js`;
8084
const cacheFile = join(opts.scriptsBuildDir, fileName);

scripts/esbuild/mock-doc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export async function buildMockDoc(opts: BuildOptions) {
3636
bundle: true,
3737
alias: mockDocAliases,
3838
logLevel: 'info',
39+
target: 'node16',
3940
};
4041

4142
const esmOptions: ESBuildOptions = {

0 commit comments

Comments
 (0)