Skip to content

Commit

Permalink
Merge pull request #4229 from GordonSmith/ESBUILD_PLUGINS
Browse files Browse the repository at this point in the history
fix:  Sourcemap for watch was different to build
  • Loading branch information
GordonSmith committed Aug 29, 2024
2 parents 9e1dd99 + 8811920 commit da124d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 54 deletions.
87 changes: 33 additions & 54 deletions packages/esbuild-plugins/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,95 +39,74 @@ export const isDevelopment = argv.mode === "development";
export const isProduction = !isDevelopment;
export const isWatch = argv.watch;

export function build(config: BuildOptions) {
if (isDevelopment && Array.isArray(config.entryPoints)) {
// eslint-disable-next-line no-console
console.log("Start: ", config.entryPoints[0], config.outfile);
}
return esbuild.build({
sourcemap: "linked",
async function buildWatch(input: string, format: Format | "umd" = "esm", external: string[] = [], config: BuildOptions): Promise<void> {

const ctx = await esbuild.context({
entryPoints: [input],
format: format as Format,
bundle: true,
minify: isProduction,
sourcemap: isDevelopment,
external,
...config,
plugins: [
...(isWatch ? [rebuildLogger(config)] : []),
...(config.plugins ?? []),
sfxWasm()
]
}).finally(() => {
});

if (isWatch) {
await ctx.watch();
} else {
if (isDevelopment && Array.isArray(config.entryPoints)) {
// eslint-disable-next-line no-console
console.log("Start: ", config.entryPoints[0], config.outfile);
}
await ctx.rebuild();
await ctx.dispose();
if (isDevelopment && Array.isArray(config.entryPoints)) {
// eslint-disable-next-line no-console
console.log("Stop: ", config.entryPoints[0], config.outfile);
}
});
}

export async function watch(config: BuildOptions) {
await build(config);
return esbuild.context({
sourcemap: "external",
...config,
plugins: [
...(config.plugins ?? []),
rebuildLogger(config),
sfxWasm()
]
}).then(ctx => {
return ctx.watch();
});
}

export function buildWatch(config: BuildOptions) {
return isWatch ? watch(config) : build(config);
}
}

export function browserTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, libraryName?: string, external: string[] = []) {
return buildWatch({
entryPoints: [input],
return buildWatch(input, format, external, {
outfile: `${output}.${format === "esm" ? "js" : `${format}.js`}`,
platform: "browser",
target: "es2022",
format: format as Format,
globalName,
bundle: true,
minify: isProduction,
external,
plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
});
}

export function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
return Promise.all([
browserTpl(input, output, "esm", globalName, libraryName, external),
browserTpl(input, output, "umd", globalName, libraryName, external)
]);
}

export function nodeTpl(input: string, output: string, format: Format | "umd" = "esm", external: string[] = []) {
return buildWatch({
entryPoints: [input],
return buildWatch(input, format, external, {
outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
platform: "node",
target: "node20",
format: format as Format,
bundle: true,
minify: isProduction,
external
target: "node20"
});
}

export function neutralTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, libraryName?: string, external: string[] = []) {
return buildWatch({
entryPoints: [input],
return buildWatch(input, format, external, {
outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
platform: "neutral",
target: "es2022",
format: format as Format,
globalName,
bundle: true,
minify: isProduction,
external,
plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
});
}

export function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
return Promise.all([
browserTpl(input, output, "esm", globalName, libraryName, external),
browserTpl(input, output, "umd", globalName, libraryName, external)
]);
}

export function nodeBoth(input: string, output: string, external: string[] = []) {
return Promise.all([
nodeTpl(input, output, "esm", external),
Expand Down
1 change: 1 addition & 0 deletions packages/loader/src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const localPackages = {
// Keep in sync with util/src/index.ts
export const hpccShims = ["loader", "codemirror-shim", "ddl-shim", "deck-shim", "dgrid-shim", "leaflet-shim", "phosphor-shim", "preact-shim"];
export const packages = [
"esbuild-plugins",
"comms", "util", "common", "layout", "phosphor", "api", "dgrid", "dgrid2", "chart", "other", "form",
"tree", "graph", "map", "map-deck", "observable-md",
"react", "composite", "marshaller", "html", "timeline", "codemirror", "eclwatch"
Expand Down

0 comments on commit da124d8

Please sign in to comment.