Skip to content

Commit

Permalink
Use npm instead of yarn to build Theia
Browse files Browse the repository at this point in the history
Fixes eclipse-theia#13948

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Nov 24, 2024
1 parent 2a0232d commit c5b0db8
Show file tree
Hide file tree
Showing 46 changed files with 31,136 additions and 13,608 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
root = true

[*]
insert_final_newline = true
end_of_line = lf
indent_style = space

Expand Down
6 changes: 1 addition & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ module.exports = {
ignorePatterns: [
'**/{node_modules,lib}',
'plugins'
],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json'
}
]
};
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Build
shell: bash
run: |
yarn build:examples
yarn build:applications
./scripts/check_git_status.sh
env:
NODE_OPTIONS: --max_old_space_size=4096
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/performance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: |
yarn global add node-gyp
yarn --skip-integrity-check --network-timeout 100000 --ignore-engines
yarn build:examples
yarn build:applications
env:
NODE_OPTIONS: --max_old_space_size=4096
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://github.com/microsoft/vscode-ripgrep/issues/9
Expand Down
1 change: 0 additions & 1 deletion .yarnrc

This file was deleted.

4 changes: 2 additions & 2 deletions configs/base.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
}
},
"plugins": [
"@theia",
"@theia",
"@typescript-eslint",
"@typescript-eslint/tslint",
"import",
"import",
"no-null"
],
"env": {
Expand Down
24 changes: 19 additions & 5 deletions dev-packages/application-manager/src/application-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class ApplicationProcess {
}

canRun(command: string): boolean {
return fs.existsSync(this.resolveBin(command));
const binPath = this.resolveBin(this.binProjectPath, command);
return !!binPath && fs.existsSync(binPath);
}

run(command: string, args: string[], options?: cp.SpawnOptions): Promise<void> {
Expand All @@ -52,16 +53,29 @@ export class ApplicationProcess {
}

spawnBin(command: string, args: string[], options?: cp.SpawnOptions): cp.ChildProcess {
const binPath = this.resolveBin(command);
const binPath = this.resolveBin(this.binProjectPath, command);
if (!binPath) {
throw new Error(`Could not resolve ${command} relative to ${this.binProjectPath}`)
}
return this.spawn(binPath, args, {
...options,
shell: true
});
}

protected resolveBin(command: string): string {
const commandPath = path.resolve(this.binProjectPath, 'node_modules', '.bin', command);
return process.platform === 'win32' ? commandPath + '.cmd' : commandPath;
protected resolveBin(rootPath: string, command: string): string | undefined {
let commandPath = path.resolve(rootPath, 'node_modules', '.bin', command);
if (process.platform === 'win32') {
commandPath = commandPath + '.cmd';
}
if (fs.existsSync(commandPath)) {
return commandPath;
}
const parentDir = path.dirname(rootPath);
if (parentDir === rootPath) {
return undefined;
}
return this.resolveBin(parentDir, command);
}

protected promisify(command: string, p: cp.ChildProcess): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { AbstractGenerator } from './abstract-generator';
export class WebpackGenerator extends AbstractGenerator {

async generate(): Promise<void> {
await this.write(this.genConfigPath, this.compileWebpackConfig());
await this.write(this.genConfigPath, this.compileWebpackConfig());
if (!this.pck.isBrowserOnly()) {
await this.write(this.genNodeConfigPath, this.compileNodeWebpackConfig());
}
if (await this.shouldGenerateUserWebpackConfig()) {
await this.write(this.configPath, this.compileUserWebpackConfig());
}
}
}

protected async shouldGenerateUserWebpackConfig(): Promise<boolean> {
if (!(await fs.pathExists(this.configPath))) {
Expand All @@ -50,10 +50,6 @@ export class WebpackGenerator extends AbstractGenerator {
return this.pck.path('gen-webpack.node.config.js');
}

protected resolve(moduleName: string, path: string): string {
return this.pck.resolveModulePath(moduleName, path).split(paths.sep).join('/');
}

protected compileWebpackConfig(): string {
return `/**
* Don't touch this file. It will be regenerated by theia build.
Expand Down
16 changes: 6 additions & 10 deletions dev-packages/application-package/src/application-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ApplicationPackageOptions {
readonly appTarget?: ApplicationProps.Target;
}

export type ApplicationModuleResolver = (modulePath: string) => string;
export type ApplicationModuleResolver = (parentPackagePath: string, modulePath: string) => string;

export class ApplicationPackage {
readonly projectPath: string;
Expand Down Expand Up @@ -109,7 +109,7 @@ export class ApplicationPackage {
(raw: PublishedNodePackage, options: ExtensionPackageOptions = {}) => this.newExtensionPackage(raw, options),
this.resolveModule
);
this._extensionPackages = collector.collect(this.pck);
this._extensionPackages = collector.collect(this.packagePath, this.pck);
}
return this._extensionPackages;
}
Expand Down Expand Up @@ -315,20 +315,16 @@ export class ApplicationPackage {
*/
get resolveModule(): ApplicationModuleResolver {
if (!this._moduleResolver) {
const resolutionPaths = this.packagePath || process.cwd();
this._moduleResolver = modulePath => {
const resolved = resolvePackagePath(modulePath, resolutionPaths);

this._moduleResolver = (parentPackagePath, modulePath) => {
const resolved = resolvePackagePath(modulePath, parentPackagePath);
if (!resolved) {
console.error(`cannot resolve ${modulePath} relative to ${parentPackagePath}`);
throw new Error('Could not resolve module: ' + modulePath);
}
return resolved;
};
}
return this._moduleResolver!;
}

resolveModulePath(moduleName: string, ...segments: string[]): string {
return paths.resolve(this.resolveModule(moduleName + '/package.json'), '..', ...segments);
}

}
20 changes: 10 additions & 10 deletions dev-packages/application-package/src/extension-package-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,42 @@ export class ExtensionPackageCollector {

constructor(
protected readonly extensionPackageFactory: (raw: PublishedNodePackage, options?: ExtensionPackageOptions) => ExtensionPackage,
protected readonly resolveModule: (modulePath: string) => string
protected readonly resolveModule: (packagepath: string, modulePath: string) => string
) { }

protected root: NodePackage;
collect(pck: NodePackage): ReadonlyArray<ExtensionPackage> {
collect(packagePath: string, pck: NodePackage): ReadonlyArray<ExtensionPackage> {
this.root = pck;
this.collectPackages(pck);
this.collectPackages(packagePath, pck);
return this.sorted;
}

protected collectPackages(pck: NodePackage): void {
protected collectPackages(packagePath: string, pck: NodePackage): void {
for (const [dependency, versionRange] of [
...Object.entries(pck.dependencies ?? {}),
...Object.entries(pck.peerDependencies ?? {})
]) {
this.collectPackage(dependency, versionRange!);
this.collectPackage(packagePath, dependency, versionRange!);
}
}

protected parent: ExtensionPackage | undefined;
protected collectPackagesWithParent(pck: NodePackage, parent: ExtensionPackage): void {
protected collectPackagesWithParent(packagePath: string, pck: NodePackage, parent: ExtensionPackage): void {
const current = this.parent;
this.parent = parent;
this.collectPackages(pck);
this.collectPackages(packagePath, pck);
this.parent = current;
}

protected collectPackage(name: string, versionRange: string): void {
protected collectPackage(parentPackagePath: string, name: string, versionRange: string): void {
if (this.visited.has(name)) {
return;
}
this.visited.set(name, true);

let packagePath: string | undefined;
try {
packagePath = this.resolveModule(name);
packagePath = this.resolveModule(parentPackagePath, name);
} catch {
console.debug(`Failed to resolve module: ${name}`);
}
Expand All @@ -75,7 +75,7 @@ export class ExtensionPackageCollector {
pck.installed = { packagePath, version, parent, transitive };
pck.version = versionRange;
const extensionPackage = this.extensionPackageFactory(pck, { alias: name });
this.collectPackagesWithParent(pck, extensionPackage);
this.collectPackagesWithParent(packagePath, pck, extensionPackage);
this.sorted.push(extensionPackage);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"theia-patch": "./bin/theia-patch.js"
},
"scripts": {
"prepare": "tsc -b",
"compile": "theiaext compile",
"lint": "theiaext lint",
"build": "theiaext build",
"watch": "theiaext watch",
Expand Down
1 change: 1 addition & 0 deletions dev-packages/ffmpeg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"src"
],
"scripts": {
"compile": "theiaext compile",
"lint": "theiaext lint",
"build": "theiaext build",
"watch": "theiaext watch",
Expand Down
3 changes: 1 addition & 2 deletions dev-packages/private-eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"description": "Custom ESLint rules for developing Theia extensions and applications",
"main": "index.js",
"scripts": {
"prepare": "tsc -b"
"compile": "theiaext compile"
},
"dependencies": {
"@theia/core": "1.55.0",
"@theia/ext-scripts": "1.55.0",
"@theia/re-exports": "1.55.0",
"js-levenshtein": "^1.1.6"
Expand Down
3 changes: 0 additions & 3 deletions dev-packages/private-eslint-plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"rules"
],
"references": [
{
"path": "../../packages/core"
},
{
"path": "../private-re-exports"
}
Expand Down
9 changes: 4 additions & 5 deletions dev-packages/private-ext-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
"bin": {
"run": "theia-run.js",
"theiaext": "theia-ext.js",
"ts-clean": "theia-ts-clean.js"
"ts-clean-dangling": "theia-ts-clean.js"
},
"theia-monorepo-scripts": {
"ext:clean": "theiaext compile:clean && theiaext lint:clean && theiaext test:clean",
"ext:build": "concurrently -n compile,lint -c blue,green \"theiaext compile\" \"theiaext lint\"",
"ext:compile": "ts-clean && tsc -b",
"ext:compile:fast": "tsc -p",
"ext:build": "ts-clean-dangling && tsc --build",
"ext:compile": "ts-clean-dangling && tsc --project .",
"ext:compile:clean": "rimraf lib *.tsbuildinfo",
"ext:lint": "eslint --cache=true --no-error-on-unmatched-pattern=true \"{src,test}/**/*.{ts,tsx}\"",
"ext:lint:clean": "rimraf .eslintcache",
Expand All @@ -23,4 +22,4 @@
"ext:test:watch": "mocha -w --config ../../configs/mocharc.yml \"./lib/**/*.*spec.js\"",
"ext:test:clean": "rimraf .nyc_output coverage"
}
}
}
7 changes: 5 additions & 2 deletions dev-packages/private-re-exports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"scripts": {
"build": "theiaext build",
"clean": "theiaext clean",
"prepare": "tsc -b",
"compile": "theiaext compile",
"lint": "theiaext lint",
"test": "theiaext test",
"watch": "theiaext watch"
Expand All @@ -30,6 +30,9 @@
"yargs": "^15.3.1"
},
"devDependencies": {
"@types/mustache": "^4.1.2"
"@types/chai": "^4.3.0",
"@types/mocha": "^10.0.0",
"@types/mustache": "^4.1.2",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ commands:
component: che-dev
command: >
killall node;
yarn && yarn download:plugins && yarn build:examples
yarn && yarn download:plugins && yarn build:applications
workdir: /projects/theia
- name: >
theia: Launch Browser Backend
Expand Down
2 changes: 1 addition & 1 deletion doc/Developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ yarn browser build
yarn electron build

# build both example applications at once:
yarn build:examples
yarn build:applications
```

To learn more and understand precisely what's going on, please look at scripts in [package.json](../package.json).
Expand Down
10 changes: 5 additions & 5 deletions examples/browser-only/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
"scripts": {
"prepare:no-native": "lerna run prepare --scope=\"@theia/re-exports\" && lerna run generate-theia-re-exports --scope=\"@theia/core\"",
"clean": "theia clean",
"build": "yarn -s compile && yarn -s bundle",
"build": "theiaext build && npm run -s bundle",
"bundle": "theia build --mode development",
"compile": "tsc -b",
"compile": "theiaext compile",
"start": "theia start",
"start:debug": "yarn -s start --log-level=debug",
"start:watch": "concurrently --kill-others -n tsc,bundle,run -c red,yellow,green \"tsc -b -w --preserveWatchOutput\" \"yarn -s watch:bundle\" \"yarn -s start\"",
"watch": "concurrently --kill-others -n tsc,bundle -c red,yellow \"tsc -b -w --preserveWatchOutput\" \"yarn -s watch:bundle\"",
"start:debug": "npm run -s start --log-level=debug",
"start:watch": "concurrently --kill-others -n tsc,bundle,run -c red,yellow,green \"tsc -b -w --preserveWatchOutput\" \"npm run -s watch:bundle\" \"npm run -s start\"",
"watch": "concurrently --kill-others -n tsc,bundle -c red,yellow \"tsc -b -w --preserveWatchOutput\" \"npm run -s watch:bundle\"",
"watch:bundle": "theia build --watch --mode development",
"watch:compile": "tsc -b -w"
},
Expand Down
18 changes: 9 additions & 9 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@
},
"scripts": {
"clean": "theia clean",
"build": "yarn -s compile && yarn -s bundle",
"build:production": "yarn -s compile && yarn -s bundle:production",
"bundle": "yarn rebuild && theia build --mode development",
"bundle:production": "yarn rebuild && theia build --mode production",
"build": "theiaext build && npm run -s bundle",
"build:production": "theiaext build && npm run -s bundle:production",
"bundle": "npm run rebuild && theia build --mode development",
"bundle:production": "npm run rebuild && theia build --mode production",
"compile": "tsc -b",
"coverage": "yarn -s test --test-coverage && yarn -s coverage:report",
"coverage": "npm run -s test --test-coverage && npm run -s coverage:report",
"coverage:clean": "rimraf .nyc_output && rimraf coverage",
"coverage:report": "nyc report --reporter=html",
"rebuild": "theia rebuild:browser --cacheRoot ../..",
"start": "theia start --plugins=local-dir:../../plugins --ovsx-router-config=../ovsx-router-config.json",
"start:debug": "yarn -s start --log-level=debug",
"start:watch": "concurrently --kill-others -n tsc,bundle,run -c red,yellow,green \"tsc -b -w --preserveWatchOutput\" \"yarn -s watch:bundle\" \"yarn -s start\"",
"start:debug": "npm run -s start --log-level=debug",
"start:watch": "concurrently --kill-others -n tsc,bundle,run -c red,yellow,green \"tsc -b -w --preserveWatchOutput\" \"npm run -s watch:bundle\" \"npm run -s start\"",
"test": "theia test . --plugins=local-dir:../../plugins --test-spec=../api-tests/**/*.spec.js",
"test:debug": "yarn -s test --test-inspect",
"watch": "concurrently --kill-others -n tsc,bundle -c red,yellow \"tsc -b -w --preserveWatchOutput\" \"yarn -s watch:bundle\"",
"test:debug": "npm run -s test --test-inspect",
"watch": "concurrently --kill-others -n tsc,bundle -c red,yellow \"tsc -b -w --preserveWatchOutput\" \"npm run -s watch:bundle\"",
"watch:bundle": "theia build --watch --mode development",
"watch:compile": "tsc -b -w"
},
Expand Down
Loading

0 comments on commit c5b0db8

Please sign in to comment.