Skip to content

Commit

Permalink
chore: configure build to prefer esm, split
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Sep 26, 2024
1 parent 7eb2c18 commit 1e1db61
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 38 deletions.
1 change: 1 addition & 0 deletions .scripts/release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function call(command) {
async function run() {
await call(`git checkout main`);
await call(`git pull`);
await call(`npm run clean`);
await call(`npm clean-install`);
await call(`npm run build`);
await call(`npm run release`);
Expand Down
6 changes: 1 addition & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/language-server/bin/some-sass-language-server
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const args = process.argv;

if (args.includes("--version") || args.includes("-v") || args.includes("-V")) {
try {
const pkg = fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf-8");
const pkg = fs.readFileSync(
path.join(__dirname, "..", "package.json"),
"utf-8",
);
const json = JSON.parse(pkg);
if (!json.version) {
throw new Error();
Expand All @@ -25,4 +28,4 @@ For documentation, visit https://wkillerud.github.io/some-sass/language-server/g
return;
}

require(path.join(__dirname, "..", "dist", "node-server.js"));
require(path.join(__dirname, "..", "dist", "node-main.js"));
6 changes: 5 additions & 1 deletion packages/language-server/rspack.browser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = {
context: __dirname,
target: "webworker",
entry: {
"browser-server": "./src/browser-server.ts",
"browser-main": "./src/browser-main.ts",
},
output: {
libraryTarget: "var",
Expand Down Expand Up @@ -42,6 +42,7 @@ const config = {
resolve: {
extensions: [".ts", ".js"],
mainFields: ["browser", "module", "main"],
conditionNames: ["import", "require", "default"],
fallback: {
events: require.resolve("events/"),
path: require.resolve("path-browserify"),
Expand All @@ -54,6 +55,9 @@ const config = {
new rspack.ProvidePlugin({
process: "process/browser",
}),
new rspack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
process.env.RSDOCTOR && new RsdoctorRspackPlugin(),
].filter(Boolean),
Expand Down
4 changes: 3 additions & 1 deletion packages/language-server/rspack.node.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { RsdoctorRspackPlugin } = require("@rsdoctor/rspack-plugin");
const config = {
target: "node",
entry: {
"node-server": "./src/node-server.ts",
"node-main": "./src/node-main.ts",
},
output: {
filename: "[name].js",
Expand All @@ -16,6 +16,8 @@ const config = {
},
resolve: {
extensions: [".ts", ".js"],
conditionNames: ["import", "require", "default"],
mainFields: ["module", "main"],
},
module: {
rules: [
Expand Down
4 changes: 4 additions & 0 deletions packages/language-server/src/browser-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
async function setupBrowser() {
await import("./browser-server");
}
setupBrowser();
4 changes: 4 additions & 0 deletions packages/language-server/src/node-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
async function setupNode() {
await import("./node-server");
}
setupNode();
1 change: 1 addition & 0 deletions packages/vscode-css-languageservice/src/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"inlineSourceMap": false,
"declaration": true,
"strict": true,
"stripInternal": true,
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-css-languageservice/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "umd",
"moduleResolution": "node",
"sourceMap": true,
"inlineSourceMap": false,
"declaration": true,
"strict": true,
"stripInternal": true,
Expand Down
4 changes: 3 additions & 1 deletion vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@
"some-sass-language-server": "1.8.3",
"vscode-css-languageservice": "6.3.1",
"vscode-languageclient": "9.0.1",
"vscode-uri": "3.0.7"
"vscode-uri": "3.0.8"
},
"devDependencies": {
"@types/mocha": "10.0.7",
Expand All @@ -1392,6 +1392,8 @@
"build:development:browser": "npm run build:browser -- --mode=development",
"build:production:node": "npm run build:node -- --mode=production",
"build:production:browser": "npm run build:browser -- --mode=production",
"doctor:node": "RSDOCTOR=true run-s build:production:node",
"doctor:browser": "RSDOCTOR=true run-s build:production:browser",
"start:web": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=.",
"lint": "eslint \"**/*.ts\" --cache",
"pretest:e2e": "run-s clean build:production:*",
Expand Down
25 changes: 14 additions & 11 deletions vscode-extension/rspack.browser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ const config = {
"browser-client": "./src/browser-client.ts",
},
output: {
libraryTarget: "commonjs",

path: path.join(__dirname, "./dist"),
filename: "[name].js",
path: path.join(__dirname, "./dist"),
libraryTarget: "commonjs",
},
externals: {
vscode: "commonjs vscode",
Expand All @@ -24,8 +23,8 @@ const config = {
devtool: false,
resolve: {
extensions: [".ts", ".js"],

mainFields: ["browser", "module", "main"], // prefer `browser` entry point in imported modules
mainFields: ["browser", "module", "main"],
conditionNames: ["import", "require", "default"],
fallback: {
events: require.resolve("events/"),
assert: require.resolve("assert"),
Expand Down Expand Up @@ -55,23 +54,27 @@ const config = {
},
],
},
};

module.exports = (env, argv) => {
config.plugins?.push(
plugins: [
new rspack.ProvidePlugin({
process: "process/browser",
}),
new rspack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
new rspack.CopyRspackPlugin({
patterns: [
{
from: "../node_modules/some-sass-language-server/dist/browser-server.*",
from: "../node_modules/some-sass-language-server/dist/**/*.js",
to: "[name][ext]",
},
],
}),
);
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
process.env.RSDOCTOR && new RsdoctorRspackPlugin(),
].filter(Boolean),
};

module.exports = (env, argv) => {
if (argv.mode === "development") {
config.devtool = "source-map";
}
Expand Down
27 changes: 15 additions & 12 deletions vscode-extension/rspack.node.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require("path");
const rspack = require("@rspack/core");
const { RsdoctorRspackPlugin } = require("@rsdoctor/rspack-plugin");

/** @type {import('@rspack/core').Configuration} **/
const config = {
Expand All @@ -21,8 +22,21 @@ const config = {
},
resolve: {
extensions: [".ts", ".js"],
conditionNames: ["import", "require", "default"],
mainFields: ["module", "main"],
},
plugins: [],
plugins: [
new rspack.CopyRspackPlugin({
patterns: [
{
from: "../node_modules/some-sass-language-server/dist/**/*.js",
to: "[name][ext]",
},
],
}),
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
process.env.RSDOCTOR && new RsdoctorRspackPlugin(),
].filter(Boolean),
devtool: false,
module: {
rules: [
Expand All @@ -44,17 +58,6 @@ const config = {
};

module.exports = (env, argv) => {
config.plugins?.push(
new rspack.CopyRspackPlugin({
patterns: [
{
from: "../node_modules/some-sass-language-server/dist/node-server.*",
to: "[name][ext]",
},
],
}),
);

if (argv.mode === "development") {
config.devtool = "source-map";
}
Expand Down
3 changes: 3 additions & 0 deletions vscode-extension/rspack.test-web.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const browserTestsConfig = {
},
],
},
performance: {
hints: false,
},
plugins: [
new rspack.ProvidePlugin({
process: "process/browser",
Expand Down
5 changes: 1 addition & 4 deletions vscode-extension/src/browser-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ function createWorkerLanguageClient(
context: ExtensionContext,
clientOptions: LanguageClientOptions,
) {
const serverMain = Uri.joinPath(
context.extensionUri,
"dist/browser-server.js",
);
const serverMain = Uri.joinPath(context.extensionUri, "dist/browser-main.js");
const worker = new Worker(serverMain.toString(/* skipEncoding */ true));

return new LanguageClient(
Expand Down
2 changes: 1 addition & 1 deletion vscode-extension/src/node-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function getOuterMostWorkspaceFolder(folder: WorkspaceFolder): WorkspaceFolder {
}

export async function activate(context: ExtensionContext): Promise<void> {
const serverModule = context.asAbsolutePath(`./dist/node-server.js`);
const serverModule = context.asAbsolutePath(`./dist/node-main.js`);

async function didOpenTextDocument(document: TextDocument): Promise<void> {
if (
Expand Down

0 comments on commit 1e1db61

Please sign in to comment.