Skip to content

Commit 8de9848

Browse files
130715: Made generate:decorator:registries compatible with new @DSpace imports
1 parent e404968 commit 8de9848

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

scripts/generate-decorator-registries.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import {
55
readFileSync,
66
rmSync,
77
writeFileSync,
8-
} from 'fs';
9-
import { sync } from 'glob';
8+
} from 'node:fs';
109
import {
1110
basename,
1211
dirname,
1312
join,
1413
relative,
1514
resolve,
16-
} from 'path';
15+
} from 'node:path';
16+
17+
import { sync } from 'glob';
1718
import {
1819
createSourceFile,
1920
forEachChild,
@@ -28,6 +29,7 @@ import {
2829
isNumericLiteral,
2930
isPropertyAccessExpression,
3031
isStringLiteral,
32+
Node,
3133
ScriptTarget,
3234
SourceFile,
3335
StringLiteral,
@@ -203,7 +205,7 @@ const writeRegistryFile = (
203205
const mapName = getDecoratorConstName(decoratorConfig.name) + '_MAP';
204206
const functionName = `${decoratorConfig.name}CreateMap`;
205207
const mapVarName = `${decoratorConfig.name}Map`;
206-
let content = '';
208+
let content: string;
207209

208210
// Start the registry file with the import statements, if any.
209211
content = generateImportStatements(components);
@@ -250,11 +252,14 @@ const generateImportsMap = (file: SourceFile): Map<string, string> => {
250252
* Then resolve that to a relative path, relative to the decorator registries directory.
251253
*/
252254
const parseImportPath = (allImports: Map<string, string>, arg: any, filePath: string): string => {
253-
let absoluteImportPath = allImports.get(arg.text);
254-
if (!absoluteImportPath.includes('src/app')) {
255-
absoluteImportPath = resolve(dirname(filePath), allImports.get(arg.text));
255+
const absoluteImportPath = allImports.get(arg.text);
256+
if (absoluteImportPath.startsWith('.')) {
257+
return relative(REGISTRY_OUTPUT_DIR, resolve(dirname(filePath), allImports.get(arg.text)));
258+
}
259+
if (absoluteImportPath.startsWith('src/app')) {
260+
return relative(REGISTRY_OUTPUT_DIR, absoluteImportPath);
256261
}
257-
return relative(REGISTRY_OUTPUT_DIR, absoluteImportPath);
262+
return absoluteImportPath;
258263
};
259264

260265
/**
@@ -266,7 +271,7 @@ const parseDecoratorArguments = (
266271
) => {
267272
const args: any[] = [];
268273
const argImports: Map<string, string> = new Map();
269-
decorator.expression.arguments.forEach((arg) => {
274+
decorator.expression.arguments.forEach((arg: Node) => {
270275
// e.g. @decorator('range')
271276
if (isStringLiteral(arg)) {
272277
args.push(arg.text);

0 commit comments

Comments
 (0)