Skip to content

Commit

Permalink
Merge pull request #197 from jvalue/publish-language-server
Browse files Browse the repository at this point in the history
Improve build scripts
  • Loading branch information
felix-oq authored Mar 7, 2023
2 parents a3315c3 + 41067b5 commit baf90e2
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 69 deletions.
24 changes: 22 additions & 2 deletions libs/language-server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,31 @@
"passWithNoTests": true
}
},
"publish": {
"pre-publish": {
"executor": "nx:run-commands",
"dependsOn": ["build"],
"options": {
"commands": ["node tools/scripts/publish.mjs @jvalue/language-server"]
"commands": [
"node tools/scripts/relax-peer-dependency-versions.mjs @jvalue/language-server"
]
}
},
"publish": {
"executor": "nx:run-commands",
"dependsOn": ["pre-publish"],
"options": {
"commands": [
"node tools/scripts/publish.mjs @jvalue/language-server"
]
}
},
"pack": {
"executor": "nx:run-commands",
"dependsOn": ["pre-publish"],
"options": {
"commands": [
"node tools/scripts/pack.mjs @jvalue/language-server"
]
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion libs/monaco-editor/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"dependsOn": ["build"],
"options": {
"commands": [
"node tools/scripts/monaco-editor/fix-peer-dependencies.mjs @jvalue/monaco-editor"
"node tools/scripts/relax-peer-dependency-versions.mjs @jvalue/monaco-editor",
"node tools/scripts/monaco-editor/delete-vscode-peer-dependency.mjs @jvalue/monaco-editor",
"node tools/scripts/monaco-editor/relax-react-version.mjs @jvalue/monaco-editor"
]
}
},
Expand Down
23 changes: 23 additions & 0 deletions tools/scripts/monaco-editor/delete-vscode-peer-dependency.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {getOutputPath, parsePackageJson, writePackageJson} from "../shared-util.mjs";

// Executing this script: node path/to/delete-vscode-peer-dependency.mjs {projectName}
const [, , projectName] = process.argv;
process.chdir(getOutputPath(projectName));

const packageJson = parsePackageJson();

/*
In our editor, we perform imports from a package called "vscode".
This is however not the true name of the package.
The actual name of the package is `@codingame/monaco-vscode-api`.
`monaco-languageclient` renames this package (for whatever reason), see
https://github.com/TypeFox/monaco-languageclient/blob/c5511b19e95e237c3f95a0fc0588769263f3ba40/packages/client/package.json#L56
This is a problem for our bundler, because it seems unable to detect that the package has been renamed.
Thus, it creates an entry in `package.json`, saying that our library depends on `vscode` instead of `@codingame/monaco-vscode-api`.
Since this package is a peer dependency of `monaco-languageclient` anyways, we can simply remove the entry for `vscode` to fix the problem.
*/
delete packageJson.peerDependencies.vscode;

writePackageJson(packageJson);
66 changes: 0 additions & 66 deletions tools/scripts/monaco-editor/fix-peer-dependencies.mjs

This file was deleted.

12 changes: 12 additions & 0 deletions tools/scripts/monaco-editor/relax-react-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {getOutputPath, parsePackageJson, writePackageJson} from "../shared-util.mjs";

// Executing this script: node path/to/relax-react-version.mjs {projectName}
const [, , projectName] = process.argv;
process.chdir(getOutputPath(projectName));

const packageJson = parsePackageJson();

// By default, this value is set to the exact React version we are using. This makes it hard to use the package in environments where a different React version is present.
packageJson.peerDependencies.react = '>= 17';

writePackageJson(packageJson);
45 changes: 45 additions & 0 deletions tools/scripts/relax-peer-dependency-versions.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
invariant,
parsePackageVersion,
writePackageJson,
parsePackageJson,
getOutputPath
} from './shared-util.mjs';

/**
* This script applies the following changes to the peer dependencies:
* - If a package version like "1.2.3" is specified, it gets rewritten to "^1.0.0".
* - A special case of the previous one: If a package version like "0.1.2" is specified, then this version gets rewritten to "^0.1.0". This is because work-in-progress packages are often versioned in a way that minor releases indicate larger changes.
*
* Summary:
*
* ``` txt
* "foo": "1.2.3"
* --> "foo": "^1.0.0"
*
* "foo": "0.1.2"
* --> foo": "^0.1.0"
* ```
*/

// Executing this script: node path/to/relax-peer-dependency-versions.mjs {projectName}
const [, , projectName] = process.argv;
process.chdir(getOutputPath(projectName));

const packageJson = parsePackageJson();
invariant(packageJson.peerDependencies, 'Found no peer dependencies in package.json');

for (const [packageName, packageVersion] of Object.entries(
packageJson.peerDependencies,
)) {
const parsedVersion = parsePackageVersion(packageVersion);
let newVersion;
if (parsedVersion.major < 1) {
newVersion = `^0.${parsedVersion.minor}.0`;
} else {
newVersion = `^${parsedVersion.major}.0.0`;
}
packageJson.peerDependencies[packageName] = newVersion;
}

writePackageJson(packageJson);

0 comments on commit baf90e2

Please sign in to comment.