mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
8d7f1098d8
As outlined in the previous commit which enabled the `esModuleInterop` TypeScript compiler option, we need to update all namespace imports for `typescript` to default imports. This is needed to allow for TypeScript to be imported at runtime from an ES module. Similar changes are needed for modules like `semver` where the types incorrectly suggest named exports that will not exist at runtime when imported from ESM. This commit refactors all imports to match with the lint rule we have configured in the previous commit. See the previous commit for more details on why certain imports have been changed. A special case are the imports to `@babel/core` and `@babel/types`. For these a special interop is needed as both default imports, or named imports break the other module format. e.g default imports would work well for ESM, but it breaks for CJS. For CJS, the named imports would only work, but in ESM, only the default export exist. We work around this for now until the devmode is using ESM as well (which would be consistent with prodmode and gives us more valuable test results). More details on the interop can be found in the `babel_core.ts` files (two interops are needed for both localize/or the compiler-cli). PR Close #43431
39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
import {NodeJSFileSystem} from '../../../src/ngtsc/file_system';
|
|
import {ConsoleLogger, LogLevel} from '../../../src/ngtsc/logging';
|
|
import {LinkerOptions} from '../../src/file_linker/linker_options';
|
|
|
|
import {ConfigAPI, PluginObj} from './babel_core';
|
|
import {createEs2015LinkerPlugin} from './es2015_linker_plugin';
|
|
|
|
/**
|
|
* This is the Babel plugin definition that is provided as a default export from the package, such
|
|
* that the plugin can be used using the module specifier of the package. This is the recommended
|
|
* way of integrating the Angular Linker into a build pipeline other than the Angular CLI.
|
|
*
|
|
* When the module specifier `@angular/compiler-cli/linker/babel` is used as a plugin in a Babel
|
|
* configuration, Babel invokes this function (by means of the default export) to create the plugin
|
|
* instance according to the provided options.
|
|
*
|
|
* The linker plugin that is created uses the native NodeJS filesystem APIs to interact with the
|
|
* filesystem. Any logging output is printed to the console.
|
|
*
|
|
* @param api Provides access to the Babel environment that is configuring this plugin.
|
|
* @param options The plugin options that have been configured.
|
|
*/
|
|
export function defaultLinkerPlugin(api: ConfigAPI, options: Partial<LinkerOptions>): PluginObj {
|
|
api.assertVersion(7);
|
|
|
|
return createEs2015LinkerPlugin({
|
|
...options,
|
|
fileSystem: new NodeJSFileSystem(),
|
|
logger: new ConsoleLogger(LogLevel.info),
|
|
});
|
|
}
|