Skip to content

Commit d0c5ce5

Browse files
fix(build): fix build after dependency updates (#6251)
* fix(build): fix build after dependency updates * more build improvements * prettier
1 parent fa9a2cc commit d0c5ce5

File tree

9 files changed

+37
-76
lines changed

9 files changed

+37
-76
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"build": "npm run clean && npm run tsc.prod && npm run ts scripts/index.ts -- --prod --ci",
9898
"build.watch": "npm run build -- --watch",
9999
"build.updateSelectorEngine": "npm run ts scripts/updateSelectorEngine.ts",
100-
"clean": "rimraf build/ cli/ compiler/ dev-server/ internal/ mock-doc/ sys/ testing/ && npm run clean:scripts && npm run clean.screenshots",
100+
"clean": "rimraf --max-retries=2 build/ cli/ compiler/ dev-server/ internal/ mock-doc/ sys/node/ sys/ testing/ && npm run clean:scripts && npm run clean.screenshots",
101101
"clean.screenshots": "rimraf test/end-to-end/screenshot/builds test/end-to-end/screenshot/images",
102102
"clean:scripts": "rimraf scripts/build",
103103
"lint": "eslint 'bin/*' 'scripts/*.ts' 'scripts/**/*.ts' 'src/*.ts' 'src/**/*.ts' 'src/**/*.tsx' 'test/wdio/**/*.tsx'",

scripts/esbuild/dev-server.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import ts from 'typescript';
99
import { getBanner } from '../utils/banner';
1010
import { type BuildOptions, createReplaceData } from '../utils/options';
1111
import { writePkgJson } from '../utils/write-pkg-json';
12-
import { bundleExternal, sysNodeBundleCacheDir } from './sys-node';
1312
import { externalAlias, getBaseEsbuildOptions, getEsbuildAliases, getFirstOutputFile, runBuilds } from './utils';
1413
import { createContentTypeData } from './utils/content-types';
1514

@@ -64,20 +63,7 @@ export async function buildDevServer(opts: BuildOptions) {
6463
const xdgOpenDestPath = join(opts.output.devServerDir, 'xdg-open');
6564
await fs.copy(xdgOpenSrcPath, xdgOpenDestPath);
6665

67-
const cachedDir = join(opts.scriptsBuildDir, sysNodeBundleCacheDir);
68-
await Promise.all([
69-
bundleExternal(opts, opts.output.devServerDir, cachedDir, 'ws.js'),
70-
bundleExternal(opts, opts.output.devServerDir, cachedDir, 'open-in-editor-api.js'),
71-
]);
72-
73-
const external = [
74-
...builtinModules,
75-
// ws.js is externally bundled
76-
'./ws.js',
77-
// open-in-editor-api is externally bundled
78-
'./open-in-editor-api',
79-
];
80-
66+
const external = [...builtinModules];
8167
const devServerAliases = {
8268
...getEsbuildAliases(),
8369
glob: '../../sys/node/glob.js',

scripts/esbuild/sys-node.ts

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,12 @@ async function sysNodeExternalBundles(opts: BuildOptions) {
9090
const cachedDir = path.join(opts.scriptsBuildDir, sysNodeBundleCacheDir);
9191

9292
await fs.ensureDir(cachedDir);
93-
9493
await Promise.all([
9594
bundleExternal(opts, opts.output.sysNodeDir, cachedDir, 'autoprefixer.js'),
9695
bundleExternal(opts, opts.output.sysNodeDir, cachedDir, 'glob.js'),
9796
bundleExternal(opts, opts.output.sysNodeDir, cachedDir, 'graceful-fs.js'),
9897
bundleExternal(opts, opts.output.sysNodeDir, cachedDir, 'node-fetch.js'),
9998
bundleExternal(opts, opts.output.sysNodeDir, cachedDir, 'prompts.js'),
100-
// TODO(STENCIL-1052): remove next two entries once Rollup -> esbuild migration is complete
101-
bundleExternal(opts, opts.output.devServerDir, cachedDir, 'open-in-editor-api.js'),
102-
bundleExternal(opts, opts.output.devServerDir, cachedDir, 'ws.js'),
10399
]);
104100

105101
/**
@@ -110,18 +106,6 @@ async function sysNodeExternalBundles(opts: BuildOptions) {
110106
const globOutputPath = path.join(opts.output.sysNodeDir, 'glob.js');
111107
const glob = fs.readFileSync(globOutputPath, 'utf8');
112108
fs.writeFileSync(globOutputPath, glob.replace(/require\("node:/g, 'require("'));
113-
114-
// open-in-editor's visualstudio.vbs file
115-
// TODO(STENCIL-1052): remove once Rollup -> esbuild migration is complete
116-
const visualstudioVbsSrc = path.join(opts.nodeModulesDir, 'open-in-editor', 'lib', 'editors', 'visualstudio.vbs');
117-
const visualstudioVbsDesc = path.join(opts.output.devServerDir, 'visualstudio.vbs');
118-
await fs.copy(visualstudioVbsSrc, visualstudioVbsDesc);
119-
120-
// copy open's xdg-open file
121-
// TODO(STENCIL-1052): remove once Rollup -> esbuild migration is complete
122-
const xdgOpenSrcPath = path.join(opts.nodeModulesDir, 'open', 'xdg-open');
123-
const xdgOpenDestPath = path.join(opts.output.devServerDir, 'xdg-open');
124-
await fs.copy(xdgOpenSrcPath, xdgOpenDestPath);
125109
}
126110

127111
export function bundleExternal(opts: BuildOptions, outputDir: string, cachedDir: string, entryFileName: string) {
@@ -184,34 +168,40 @@ export function bundleExternal(opts: BuildOptions, outputDir: string, cachedDir:
184168
mode: 'production',
185169
};
186170

171+
console.log(`[sys-node] bundleExternal ${entryFileName} via webpack`);
187172
webpack(webpackConfig, async (err, stats) => {
188-
const { minify } = await import('terser');
189-
if (err && err.message) {
190-
rejectBundle(err);
191-
} else if (stats) {
192-
const info = stats.toJson({ errors: true });
193-
if (stats.hasErrors() && info && info.errors) {
194-
const webpackError = info.errors.join('\n');
195-
rejectBundle(webpackError);
196-
} else {
197-
let code = await fs.readFile(outputFile, 'utf8');
198-
199-
if (opts.isProd) {
200-
try {
201-
const minifyResults = await minify(code);
202-
if (minifyResults.code) {
203-
code = minifyResults.code;
173+
try {
174+
console.log(`[sys-node] bundleExternal ${entryFileName} success, err: ${err}, stats: ${stats}`);
175+
const { minify } = await import('terser');
176+
if (err && err.message) {
177+
rejectBundle(err);
178+
} else if (stats) {
179+
const info = stats.toJson({ errors: true });
180+
if (stats.hasErrors() && info && info.errors) {
181+
const webpackError = info.errors.join('\n');
182+
rejectBundle(webpackError);
183+
} else {
184+
let code = await fs.readFile(outputFile, 'utf8');
185+
186+
if (opts.isProd) {
187+
try {
188+
const minifyResults = await minify(code);
189+
if (minifyResults.code) {
190+
code = minifyResults.code;
191+
}
192+
} catch (e) {
193+
rejectBundle(e);
194+
return;
204195
}
205-
} catch (e) {
206-
rejectBundle(e);
207-
return;
208196
}
209-
}
210-
await fs.writeFile(cachedFile, code);
211-
await fs.writeFile(outputFile, code);
197+
await fs.writeFile(cachedFile, code);
198+
await fs.writeFile(outputFile, code);
212199

213-
resolveBundle();
200+
resolveBundle();
201+
}
214202
}
203+
} catch (e) {
204+
rejectBundle(e);
215205
}
216206
});
217207
});

scripts/esbuild/utils/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ export function getEsbuildAliases(): Record<string, string> {
2222
'@stencil/core/internal/testing': '../internal/testing/index.js',
2323
'@stencil/core/cli': '../cli/index.cjs',
2424
'@sys-api-node': '../sys/node/index.js',
25-
26-
// dev server related aliases
27-
ws: './ws.js',
2825
};
2926
}
3027

scripts/test/validate-build.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ const pkgs: TestPackage[] = [
3030
'dev-server/templates/directory-index.html',
3131
'dev-server/templates/initial-load.html',
3232
'dev-server/connector.html',
33-
'dev-server/open-in-editor-api.js',
3433
'dev-server/server-process.js',
3534
'dev-server/server-worker-thread.js',
3635
'dev-server/visualstudio.vbs',
37-
'dev-server/ws.js',
3836
'dev-server/xdg-open',
3937
],
4038
},

src/dev-server/server-web-socket.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { noop } from '@utils';
22
import type { Server } from 'http';
3-
import ws from 'ws';
3+
import WebSocket, { type ServerOptions, WebSocketServer } from 'ws';
44

55
import type * as d from '../declarations';
66

77
export function createWebSocket(
88
httpServer: Server,
99
onMessageFromClient: (msg: d.DevServerMessage) => void,
1010
): DevWebSocket {
11-
const wsConfig: ws.ServerOptions = {
11+
const wsConfig: ServerOptions = {
1212
server: httpServer,
1313
};
1414

15-
const wsServer: ws.Server = new ws.Server(wsConfig);
15+
const wsServer = new WebSocketServer(wsConfig);
1616

17-
function heartbeat(this: ws) {
17+
function heartbeat(this: WebSocket) {
1818
// we need to coerce the `ws` type to our custom `DevWS` type here, since
1919
// this function is going to be passed in to `ws.on('pong'` which expects
2020
// to be passed a function where `this` is bound to `ws`.
@@ -84,6 +84,6 @@ export interface DevWebSocket {
8484
close: () => Promise<void>;
8585
}
8686

87-
interface DevWS extends ws {
87+
interface DevWS extends WebSocket {
8888
isAlive: boolean;
8989
}

src/sys/node/bundles/open-in-editor-api.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/sys/node/bundles/ws.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"jsxFragmentFactory": "Fragment",
1313
"lib": ["dom", "es2021"],
1414
"module": "esnext",
15-
"moduleResolution": "node",
15+
"moduleResolution": "bundler",
1616
"noImplicitAny": true,
1717
"noImplicitOverride": true,
1818
"noImplicitReturns": true,

0 commit comments

Comments
 (0)