Skip to content

Use isolated transpilation for local projects. #5202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

iclanton
Copy link
Member

Summary

This PR updates the local rigs to use @rushstack/heft-isolated-transpile-plugin for transpilation instead of TypeScript. It also starts shipping ES modules from Node projects, and rearranges some folder structures.

How it was tested

Built and ran tests.

Impacted documentation

It may be worth updating docs to mention that we ship ESM.

@iclanton iclanton force-pushed the isolated-transpile-local-projects branch from 4b51b9b to f1ee546 Compare April 21, 2025 22:40
@@ -33,4 +33,4 @@

!/includes/**
!UPGRADING.md

lib-*/root-lib/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file accepts comments, so put a file about what the heck this pattern is matching

Comment on lines +26 to +28
"sourcePath": "lib-commonjs/root-lib",
"destinationFolders": ["lib"],
"fileExtensions": [".js", ".map"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this some back-compat chicanery?

@@ -6,17 +6,17 @@
"taskPlugins": [
{
"pluginName": "copy-files-plugin",
"entryPoint": "./lib/plugins/CopyFilesPlugin",
"optionsSchema": "./lib/schemas/copy-files-options.schema.json"
"entryPoint": "./lib-commonjs/plugins/CopyFilesPlugin",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really add the .js file extension as well

@@ -89,9 +89,9 @@ function tryStartLocalHeft(): boolean {

// To avoid a loading the "resolve" NPM package, let's assume that the Heft dependency must be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the CJS and the ESM resolvers that Node uses can be invoked externally without npm packages. require.resolve is sufficient here.

@@ -9,6 +9,21 @@
},
"homepage": "https://rushstack.io/pages/heft/overview/",
"license": "MIT",
"exports": {
"./lib/*": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we may need a "./lib/*.json": "./lib-esm/*.json" rule in most package.json exports

: itemName;
folderPathQueue.push(relativeItemPath);
} else if (folderItem.isFile() && itemName.endsWith(JS_FILE_EXTENSION)) {
const fileBaseName: string = path.parse(itemName).name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just itemName.slice(0, -JS_FILE_EXTENSION.length)?

@@ -211,6 +211,20 @@ ${errorMessage}
process.exit(1);
}

const exports: typeof import('@microsoft/rush-lib') = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, avoid using the name exports as a local identifier.

}
return exports._RushInternals.loadModule(srcImportPath);
}
export default exports;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a severe breaking change. We import this module using named imports and/or a namespace import, not a default import.

Though I guess the webpack run fixes this?

@@ -29,15 +30,21 @@
},
"exports": {
".": {
"require": "./lib/index.js",
"types": "./dist/rush-resolver-cache-plugin.d.ts"
"require": "./lib-commonjs/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order here is significant (the spec dictates that the first encountered condition in the object that matches any of the requested conditions is the result), so we should probably stick to a stable order across all of our package.json files.

@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import RawScriptLoader = require('./../RawScriptLoader');
import RawScriptLoader from './../RawScriptLoader';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import RawScriptLoader from './../RawScriptLoader';
import RawScriptLoader from '../RawScriptLoader';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants