reuse import util for both tsconfig and test runner
This commit is contained in:
@@ -2,7 +2,7 @@ import { packageJsonExports, packageJsonName } from '../package/index.js';
|
||||
|
||||
export const createImportMap = (args) => {
|
||||
const imports = {
|
||||
...args.defaultImports,
|
||||
...args.additionalImports,
|
||||
};
|
||||
|
||||
// Iterate over the exports in package.json
|
||||
@@ -12,7 +12,7 @@ export const createImportMap = (args) => {
|
||||
const moduleName = key.replace(/^\.\//, '');
|
||||
|
||||
// replace ./dist-cms with src and remove /index.js
|
||||
const modulePath = value.replace(/^\.\/dist-cms/, './src').replace('.js', '.ts');
|
||||
const modulePath = value.replace(/^\.\/dist-cms/, args.rootDir).replace('.js', '.ts');
|
||||
const importAlias = `${packageJsonName}/${moduleName}`;
|
||||
|
||||
imports[importAlias] = modulePath;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { writeFileSync } from 'fs';
|
||||
import { format } from 'prettier';
|
||||
import { packageJsonName, packageJsonExports } from '../package/index.js';
|
||||
import { createImportMap } from '../importmap/index.js';
|
||||
|
||||
const tsconfigPath = 'tsconfig.json';
|
||||
const tsconfigComment = `// Don't edit this file directly. It is generated by /devops/tsconfig/index.js\n\n`;
|
||||
@@ -37,22 +37,18 @@ const tsConfigBase = {
|
||||
],
|
||||
};
|
||||
|
||||
const paths = {
|
||||
'@umbraco-cms/internal/test-utils': ['utils/test-utils.ts'],
|
||||
};
|
||||
const importmap = createImportMap({
|
||||
rootDir: './src',
|
||||
additionalImports: {
|
||||
'@umbraco-cms/internal/test-utils': './utils/test-utils.ts',
|
||||
},
|
||||
});
|
||||
|
||||
// Iterate over the exports in package.json
|
||||
for (const [key, value] of Object.entries(packageJsonExports || {})) {
|
||||
// remove leading ./
|
||||
if (value) {
|
||||
const moduleName = key.replace(/^\.\//, '');
|
||||
const paths = {};
|
||||
|
||||
// replace ./dist-cms with src and remove /index.js
|
||||
const modulePath = value.replace(/^\.\/dist-cms/, 'src').replace(/\/index.js$/, '');
|
||||
const importAlias = `${packageJsonName}/${moduleName}`;
|
||||
|
||||
paths[importAlias] = [modulePath];
|
||||
}
|
||||
for (const [key, value] of Object.entries(importmap.imports)) {
|
||||
const valueAsArray = [value];
|
||||
paths[key] = valueAsArray;
|
||||
}
|
||||
|
||||
tsConfigBase.compilerOptions.paths = paths;
|
||||
|
||||
Reference in New Issue
Block a user