snapshot of https://github.com/dream-num/univer.git (dev, 2026-09-16; blobs > 131072B omitted)
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
This commit is contained in:
42
common/shared/tsdown/utils/package.ts
Normal file
42
common/shared/tsdown/utils/package.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { IPackageJson } from '../types.ts';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
function getProductionDependencyNames(packageJson: IPackageJson) {
|
||||
const names = new Set([
|
||||
...Object.keys(packageJson.dependencies ?? {}),
|
||||
...Object.keys(packageJson.peerDependencies ?? {}),
|
||||
]);
|
||||
|
||||
const devDeps = packageJson.devDependencies ?? {};
|
||||
if ('react' in devDeps) {
|
||||
names.add('react');
|
||||
}
|
||||
|
||||
return [...names].sort((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
function normalizeIgnoredPackages(ignorePackages: string[] = []) {
|
||||
return [...new Set(ignorePackages)].sort((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the package manifest used to derive dependency externalization rules.
|
||||
*/
|
||||
export function readPackageJson(packageDir: string): IPackageJson {
|
||||
return JSON.parse(readFileSync(path.join(packageDir, 'package.json'), 'utf-8')) as IPackageJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the external package allowlist including subpath imports.
|
||||
*/
|
||||
export function createExternalPackages(packageJson: IPackageJson, ignorePackages: string[] = []) {
|
||||
const ignoredPackages = normalizeIgnoredPackages(ignorePackages);
|
||||
|
||||
return [...new Set([
|
||||
...getProductionDependencyNames(packageJson),
|
||||
...ignoredPackages,
|
||||
])]
|
||||
.sort((left, right) => left.localeCompare(right))
|
||||
.flatMap((packageName) => [packageName, `${packageName}/*`]);
|
||||
}
|
||||
Reference in New Issue
Block a user