mirror of
https://github.com/facebook/lexical.git
synced 2025-08-06 16:39:33 +08:00
[build] Chore: Upgrade rollup and vite to latest versions (#6018)
This commit is contained in:
@ -8,29 +8,81 @@
|
||||
|
||||
import type {
|
||||
ModuleExportEntry,
|
||||
NpmModuleExportEntry,
|
||||
PackageMetadata,
|
||||
} from '../../scripts/shared/PackageMetadata';
|
||||
|
||||
import {packagesManager} from '../../scripts/shared/packagesManager';
|
||||
import * as fs from 'node:fs';
|
||||
import {createRequire} from 'node:module';
|
||||
import * as path from 'node:path';
|
||||
|
||||
function toAlias(pkg: PackageMetadata, entry: ModuleExportEntry) {
|
||||
return {
|
||||
find: entry.name,
|
||||
replacement: pkg.resolve('src', entry.sourceFileName),
|
||||
};
|
||||
const require = createRequire(import.meta.url);
|
||||
const {packagesManager} =
|
||||
require('../../scripts/shared/packagesManager') as typeof import('../../scripts/shared/packagesManager');
|
||||
|
||||
const sourceModuleResolution = () => {
|
||||
function toAlias(pkg: PackageMetadata, entry: ModuleExportEntry) {
|
||||
return {
|
||||
find: entry.name,
|
||||
replacement: pkg.resolve('src', entry.sourceFileName),
|
||||
};
|
||||
}
|
||||
|
||||
return [
|
||||
...packagesManager
|
||||
.getPublicPackages()
|
||||
.flatMap((pkg) =>
|
||||
pkg.getExportedNpmModuleEntries().map(toAlias.bind(null, pkg)),
|
||||
),
|
||||
...['shared']
|
||||
.map((name) => packagesManager.getPackageByDirectoryName(name))
|
||||
.flatMap((pkg) =>
|
||||
pkg.getPrivateModuleEntries().map(toAlias.bind(null, pkg)),
|
||||
),
|
||||
];
|
||||
};
|
||||
|
||||
const distModuleResolution = (environment: 'development' | 'production') => {
|
||||
return [
|
||||
...packagesManager.getPublicPackages().flatMap((pkg) =>
|
||||
pkg
|
||||
.getNormalizedNpmModuleExportEntries()
|
||||
.map((entry: NpmModuleExportEntry) => {
|
||||
const [name, moduleExports] = entry;
|
||||
const replacements = ([environment, 'default'] as const).map(
|
||||
(condition) => pkg.resolve('dist', moduleExports.import[condition]),
|
||||
);
|
||||
const replacement = replacements.find(fs.existsSync.bind(fs));
|
||||
if (!replacement) {
|
||||
throw new Error(
|
||||
`ERROR: Missing ./${path.relative(
|
||||
'../..',
|
||||
replacements[1],
|
||||
)}. Did you run \`npm run build\` in the monorepo first?`,
|
||||
);
|
||||
}
|
||||
return {
|
||||
find: name,
|
||||
replacement,
|
||||
};
|
||||
}),
|
||||
),
|
||||
...[packagesManager.getPackageByDirectoryName('shared')].flatMap(
|
||||
(pkg: PackageMetadata) =>
|
||||
pkg.getPrivateModuleEntries().map((entry: ModuleExportEntry) => {
|
||||
return {
|
||||
find: entry.name,
|
||||
replacement: pkg.resolve('src', entry.sourceFileName),
|
||||
};
|
||||
}),
|
||||
),
|
||||
];
|
||||
};
|
||||
|
||||
export default function moduleResolution(
|
||||
environment: 'source' | 'development' | 'production',
|
||||
) {
|
||||
return environment === 'source'
|
||||
? sourceModuleResolution()
|
||||
: distModuleResolution(environment);
|
||||
}
|
||||
|
||||
const moduleResolution = [
|
||||
...packagesManager
|
||||
.getPublicPackages()
|
||||
.flatMap((pkg) =>
|
||||
pkg.getExportedNpmModuleEntries().map(toAlias.bind(null, pkg)),
|
||||
),
|
||||
...['shared']
|
||||
.map((name) => packagesManager.getPackageByDirectoryName(name))
|
||||
.flatMap((pkg) =>
|
||||
pkg.getPrivateModuleEntries().map(toAlias.bind(null, pkg)),
|
||||
),
|
||||
];
|
||||
|
||||
export default moduleResolution;
|
||||
|
Reference in New Issue
Block a user