Skip to content

Commit

Permalink
Addressing review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Dec 17, 2024
1 parent b30a1bd commit c75a1a9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 92 deletions.
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 Down
8 changes: 4 additions & 4 deletions packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ describe('Type converters:', () => {
describe('convert tasks:', () => {
const customType = 'custom';
const shellType = 'shell';
const label = 'yarn build';
const label = 'npm run build';
const source = 'source';
const command = 'yarn';
const commandLine = 'yarn run build';
const command = 'npm';
const commandLine = 'npm run build';
const args = ['run', 'build'];
const cwd = '/projects/theia';
const additionalProperty = 'some property';
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('Type converters:', () => {
...shellPluginTask, execution: {
command: {
quoting: types.ShellQuoting.Strong,
value: 'yarn'
value: 'npm'
},
args,
options: {
Expand Down
2 changes: 1 addition & 1 deletion packages/preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
"nyc": {
"extends": "../../configs/nyc.json"
}
}
}
41 changes: 15 additions & 26 deletions scripts/compile-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,8 @@ const ROOT = path.join(__dirname, '..');

const FORCE_REWRITE = process.argv.includes('--force-rewrite');

/** @type {{ [packageName: string]: YarnWorkspace }} */
const YARN_WORKSPACES = JSON.parse(cp.execSync('yarn --silent workspaces info', { cwd: ROOT }).toString());

// Add the package name inside each package object.
for (const [packageName, yarnWorkspace] of Object.entries(YARN_WORKSPACES)) {
yarnWorkspace.name = packageName;
// For some reason Yarn doesn't report local peer dependencies, so we'll manually do it:
const { peerDependencies } = require(path.resolve(ROOT, yarnWorkspace.location, 'package.json'));
if (typeof peerDependencies === 'object') {
for (const peerDependency of Object.keys(peerDependencies)) {
if (peerDependency in YARN_WORKSPACES) {
yarnWorkspace.workspaceDependencies.push(peerDependency);
}
}
}
}
const PACKAGE_LIST = JSON.parse(cp.execSync('npx lerna ls --loglevel=silent --all --json', { cwd: ROOT }).toString());
const DEPENDENCIES = JSON.parse(cp.execSync('npx lerna ls --loglevel=silent --all --graph', { cwd: ROOT }).toString());

compileTypeScriptReferences().catch(error => {
console.error(error);
Expand All @@ -62,24 +48,28 @@ compileTypeScriptReferences().catch(error => {
* This script main entry point.
*/
async function compileTypeScriptReferences() {
await Promise.all(Object.values(YARN_WORKSPACES).map(async package => {
await Promise.all(Object.values(PACKAGE_LIST).map(async package => {
const references = await getTypescriptReferences(package);
await configureTypeScriptReferences(package, references);
}))
}

/**
* @param {YarnWorkspace} requestedPackage
* @param {WorkspacePackage} requestedPackage
* @returns {Promise<string[]>} TypeScript relative project references for `requestedPackage`.
*/
async function getTypescriptReferences(requestedPackage) {
const references = await Promise.all((requestedPackage.workspaceDependencies || []).map(async dependency => {
const depWorkspace = YARN_WORKSPACES[dependency];
const depConfig = path.join(ROOT, depWorkspace.location, 'tsconfig.json');
const dependencies = DEPENDENCIES[requestedPackage.name] || [];
const references = await Promise.all(dependencies.map(async dependency => {
const depWorkspace = PACKAGE_LIST.find(package => package.name === dependency);
if (!depWorkspace) {
return undefined;
}
const depConfig = path.join(depWorkspace.location, 'tsconfig.json');
if (!await fileExists(depConfig)) {
return undefined; // ignore because dep has no tsconfig
}
return path.posix.relative(requestedPackage.location, depWorkspace.location);
return path.relative(requestedPackage.location, depWorkspace.location).replaceAll('\\', '/');
}));
return references.filter(reference => reference !== undefined);
}
Expand All @@ -88,14 +78,14 @@ async function getTypescriptReferences(requestedPackage) {
* Wires a given compilation tsconfig file according to the provided references.
* This allows TypeScript to operate in build mode.
*
* @param {YarnWorkspace} targetPackage for debug purpose.
* @param {WorkspacePackage} targetPackage for debug purpose.
* @param {string[]} expectedReferences list of paths to the related project roots.
* @returns {Promise<boolean>} rewrite was needed.
*/
async function configureTypeScriptReferences(targetPackage, expectedReferences) {
expectedReferences = [...expectedReferences].sort();
let needRewrite = FORCE_REWRITE;
const tsconfigPath = path.resolve(ROOT, targetPackage.location, 'tsconfig.json');
const tsconfigPath = path.resolve(targetPackage.location, 'tsconfig.json');
if (!await fileExists(tsconfigPath)) {
return false;
}
Expand Down Expand Up @@ -154,8 +144,7 @@ function fileExists(file) {
}

/**
* @typedef YarnWorkspace
* @typedef WorkspacePackage
* @property {string} name
* @property {string} location
* @property {string[]} [workspaceDependencies]
*/
58 changes: 0 additions & 58 deletions scripts/run-reverse-topo.js

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/translation-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getDeepLToken() {
}

function performDeepLTranslation(token) {
const childProcess = cp.spawnSync('yarn', [
const childProcess = cp.spawnSync('npx', [
'theia', 'nls-localize',
'-f', './packages/core/i18n/nls.json',
'--free-api', '-k', token
Expand Down

0 comments on commit c75a1a9

Please sign in to comment.