@travetto/doc 3.0.0-rc.1 → 3.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,24 @@
1
- type Lang = {};
2
-
3
- // TODO: Get proper typings
4
- const Prism: {
5
- plugins: { NormalizeWhitespace: Record<string, Function> };
6
- languages: Record<string, Lang>;
7
- highlight(text: string, grammar: Lang, language: string): string;
8
- } = require('prismjs');
9
-
10
- import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace';
11
- import 'prismjs/components/prism-typescript';
12
- import 'prismjs/components/prism-javascript';
13
- import 'prismjs/components/prism-css';
14
- import 'prismjs/components/prism-scss';
15
- import 'prismjs/components/prism-yaml';
16
- import 'prismjs/components/prism-json';
17
- import 'prismjs/components/prism-sql';
18
- import 'prismjs/components/prism-properties';
19
- import 'prismjs/components/prism-bash';
20
-
21
- Prism.plugins.NormalizeWhitespace.setDefaults({
1
+ import { default as prismjs } from 'prismjs';
2
+
3
+ import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.js';
4
+ import 'prismjs/components/prism-typescript.js';
5
+ import 'prismjs/components/prism-javascript.js';
6
+ import 'prismjs/components/prism-css.js';
7
+ import 'prismjs/components/prism-scss.js';
8
+ import 'prismjs/components/prism-yaml.js';
9
+ import 'prismjs/components/prism-json.js';
10
+ import 'prismjs/components/prism-sql.js';
11
+ import 'prismjs/components/prism-properties.js';
12
+ import 'prismjs/components/prism-bash.js';
13
+
14
+ prismjs.plugins.NormalizeWhitespace.setDefaults({
22
15
  'remove-trailing': true,
23
16
  'remove-indent': true,
24
17
  'left-trim': true,
25
18
  'right-trim': true
26
19
  });
27
20
 
28
- const nw = Prism.plugins.NormalizeWhitespace;
21
+ const nw = prismjs.plugins.NormalizeWhitespace;
29
22
 
30
23
  const tokenMapping: { [key: string]: string } = {
31
24
  gt: '>',
@@ -44,7 +37,7 @@ export function highlight(text: string, lang: string): string | undefined {
44
37
  .replace(/&([a-z][^;]*);/g, (a, k) => tokenMapping[k] || a);
45
38
 
46
39
  try {
47
- return Prism.highlight(text, Prism.languages[lang], lang)
40
+ return prismjs.highlight(text, prismjs.languages[lang], lang)
48
41
  .replace(/(@\s*<span[^>]*)function("\s*>)/g, (a, pre, post) => `${pre}meta${post}`)
49
42
  .replace(/[{}]/g, a => `{{'${a}'}}`);
50
43
  } catch (err) {
@@ -1,6 +1,4 @@
1
- import * as path from 'path';
2
-
3
- import { PathUtil, FsUtil, Package, EnvUtil } from '@travetto/boot';
1
+ import { path } from '@travetto/manifest';
4
2
 
5
3
  import { AllType, AllTypeMap, node as n } from '../nodes';
6
4
  import { DocNode, RenderContextShape } from '../types';
@@ -13,31 +11,15 @@ export type AllChildren = AllType;
13
11
  export class RenderContext implements RenderContextShape {
14
12
 
15
13
  file: string;
14
+ baseUrl: string;
15
+ travettoBaseUrl: string;
16
+ repoRoot: string;
16
17
 
17
- constructor(file: string) {
18
- this.file = PathUtil.resolveUnix(file);
19
- }
20
-
21
- get #repoUrl(): string {
22
- return (Package.repository?.url ?? '').replace(/[.]git$/, '');
23
- }
24
-
25
- get gitBaseUrl(): string {
26
- return `${this.#repoUrl}/tree/${EnvUtil.get('TRV_DOC_BRANCH', 'main')}`;
27
- }
28
-
29
- get travettoGitBaseUrl(): string {
30
- return this.#repoUrl.includes('travetto/travetto') ? this.gitBaseUrl : 'https://github.com/travetto/travetto/main';
31
- }
32
-
33
- get gitFolder(): string {
34
- let base = PathUtil.cwd;
35
-
36
- while (base && !(FsUtil.existsSync(PathUtil.resolveUnix(base, '.git')))) {
37
- base = path.dirname(base);
38
- }
39
-
40
- return `${this.gitBaseUrl}${PathUtil.cwd.replace(base, '')}`;
18
+ constructor(file: string, repoRoot: string, baseUrl: string, travettoBaseUrl: string) {
19
+ this.file = path.toPosix(file);
20
+ this.baseUrl = baseUrl;
21
+ this.repoRoot = repoRoot;
22
+ this.travettoBaseUrl = travettoBaseUrl;
41
23
  }
42
24
 
43
25
  toc(root: DocNode): AllTypeMap['Ordered'] {
@@ -57,15 +39,14 @@ export class RenderContext implements RenderContextShape {
57
39
  return n.Group([
58
40
  n.Comment('This file was generated by @travetto/doc and should not be modified directly'),
59
41
  n.Text('\n'),
60
- n.Comment(`Please modify ${this.file.replace(PathUtil.cwd, this.gitFolder)} and execute "npx trv doc" to rebuild`),
42
+ n.Comment(`Please modify ${this.file.replace(this.repoRoot, this.baseUrl)} and execute "npx trv doc" to rebuild`),
61
43
  ]);
62
44
  }
63
45
 
64
46
  link(text: string, line?: number | { [key: string]: unknown, line?: number }): string {
65
47
  const num = typeof line === 'number' ? line : line?.line;
66
- text = PathUtil.normalizeFrameworkPath(text);
67
- return `${text.replace(PathUtil.cwd, this.gitBaseUrl)
68
- .replace(/.*@travetto\//, `${this.travettoGitBaseUrl}/module/`)}${num ? `#L${num}` : ''}`;
48
+ return `${text.replace(this.repoRoot, this.baseUrl)
49
+ .replace(/.*@travetto\//, `${this.travettoBaseUrl}/module/`)}${num ? `#L${num}` : ''}`;
69
50
  }
70
51
 
71
52
  cleanText(a?: string): string {
@@ -60,7 +60,7 @@ ${context.cleanText(recurse(c.content))}
60
60
  case 'header':
61
61
  return `# ${recurse(c.title)}\n${c.description ? `## ${recurse(c.description)}\n` : ''}${'install' in c ? recurse(n.Install(c.package, c.package)) : ''}\n`;
62
62
  case 'text':
63
- return c.content;
63
+ return c.content.replace(/&nbsp;/g, ' ');
64
64
  }
65
65
  }
66
66
  };
@@ -1,389 +1,17 @@
1
- // Type definitions for prismjs 1.16
2
- // Project: http://prismjs.com/, https://github.com/leaverou/prism
3
- // Definitions by: Michael Schmidt <https://github.com/RunDevelopment>
4
- // ExE Boss <https://github.com/ExE-Boss>
5
- // Erik Lieben <https://github.com/eriklieben>
6
- // Andre Wiggins <https://github.com/andrewiggins>
7
- // Michał Miszczyszyn <https://github.com/mmiszy>
8
- // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9
- // TypeScript Version: 2.8
10
-
11
- export as namespace Prism;
12
- export const languages: Languages;
13
- export const plugins: Record<string, any>;
14
-
15
- /**
16
- * A function which will be invoked after an element was successfully highlighted.
17
- *
18
- * @param element The element successfully highlighted.
19
- */
20
- export type HighlightCallback = (element?: any) => void;
21
-
22
- /**
23
- * This is the most high-level function in Prism’s API.
24
- * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
25
- * each one of them.
26
- *
27
- * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
28
- *
29
- * @param [async=false] Same as in {@link Prism.highlightAllUnder}.
30
- * @param [callback] Same as in {@link Prism.highlightAllUnder}.
31
- */
32
- export function highlightAll(
33
- async?: boolean,
34
- callback?: HighlightCallback
35
- ): void;
36
-
37
- /**
38
- * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
39
- * and the language definitions to use, and returns a string with the HTML produced.
40
- *
41
- * The following hooks will be run:
42
- * 1. `before-tokenize`
43
- * 2. `after-tokenize`
44
- * 3. `wrap`: On each {@link Prism.Token}.
45
- *
46
- * @param text A string with the code to be highlighted.
47
- * @param grammar An object containing the tokens to use.
48
- *
49
- * Usually a language definition like `Prism.languages.markup`.
50
- * @param language The name of the language definition passed to `grammar`.
51
- * @returns The highlighted HTML.
52
- *
53
- * @example
54
- * Prism.highlight('var foo = true;', Prism.languages.js, 'js');
55
- */
56
- export function highlight(
57
- text: string,
58
- grammar: Grammar,
59
- language: string
60
- ): string;
61
-
62
- /**
63
- * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
64
- * and the language definitions to use, and returns an array with the tokenized code.
65
- *
66
- * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
67
- *
68
- * This method could be useful in other contexts as well, as a very crude parser.
69
- *
70
- * @param text A string with the code to be highlighted.
71
- * @param grammar An object containing the tokens to use.
72
- *
73
- * Usually a language definition like `Prism.languages.markup`.
74
- * @returns An array of strings, tokens and other arrays.
75
- */
76
- export function tokenize(
77
- text: string,
78
- grammar: Grammar
79
- ): Array<string | Token>;
80
-
81
- export interface Environment extends Record<string, any> {
82
- selector?: string;
83
- element?: any;
84
- language?: string;
85
- grammar?: Grammar;
86
- code?: string;
87
- highlightedCode?: string;
88
- type?: string;
89
- content?: string;
90
- tag?: string;
91
- classes?: string[];
92
- attributes?: Record<string, string>;
93
- parent?: Array<string | Token>;
94
- }
95
-
96
- export namespace util {
97
- interface Identifier {
98
- value: number;
99
- }
100
-
101
- /** Encode raw strings in tokens in preparation to display as HTML */
102
- function encode(tokens: TokenStream): TokenStream;
103
-
104
- /** Determine the type of the object */
105
- function type(o: null): "Null";
106
- function type(o: undefined): "Undefined";
107
- // tslint:disable:ban-types
108
- function type(o: boolean | Boolean): "Boolean";
109
- function type(o: number | Number): "Number";
110
- function type(o: string | String): "String";
111
- function type(o: Function): "Function";
112
- // tslint:enable:ban-types
113
- function type(o: RegExp): "RegExp";
114
- function type(o: any[]): "Array";
115
- function type(o: any): string;
116
-
117
- /** Get the unique id of this object or give it one if it does not have one */
118
- function objId(obj: any): Identifier;
119
-
120
- /** Deep clone a language definition (e.g. to extend it) */
121
- function clone<T>(o: T): T;
122
- }
123
-
124
- export type GrammarValue = RegExp | TokenObject | Array<RegExp | TokenObject>;
125
- export type Grammar = GrammarRest & Record<string, GrammarValue>;
126
- export interface GrammarRest {
127
- keyword?: GrammarValue;
128
- number?: GrammarValue;
129
- function?: GrammarValue;
130
- string?: GrammarValue;
131
- boolean?: GrammarValue;
132
- operator?: GrammarValue;
133
- punctuation?: GrammarValue;
134
- atrule?: GrammarValue;
135
- url?: GrammarValue;
136
- selector?: GrammarValue;
137
- property?: GrammarValue;
138
- important?: GrammarValue;
139
- style?: GrammarValue;
140
- comment?: GrammarValue;
141
- "class-name"?: GrammarValue;
142
-
143
- /**
144
- * An optional grammar object that will appended to this grammar.
145
- */
146
- rest?: Grammar;
147
- }
148
-
149
- /**
150
- * The expansion of a simple `RegExp` literal to support additional properties.
151
- */
152
- export interface TokenObject {
153
- /**
154
- * The regular expression of the token.
155
- */
156
- pattern: RegExp;
157
-
158
- /**
159
- * If `true`, then the first capturing group of `pattern` will (effectively) behave as a lookbehind
160
- * group meaning that the captured text will not be part of the matched text of the new token.
161
- */
162
- lookbehind?: boolean;
163
-
164
- /**
165
- * Whether the token is greedy.
166
- *
167
- * @default false
168
- */
169
- greedy?: boolean;
170
-
171
- /**
172
- * An optional alias or list of aliases.
173
- */
174
- alias?: string | string[];
175
-
176
- /**
177
- * The nested tokens of this token.
178
- *
179
- * This can be used for recursive language definitions.
180
- *
181
- * Note that this can cause infinite recursion.
182
- */
183
- inside?: Grammar;
184
- }
185
- export type Languages = LanguageMapProtocol & LanguageMap;
186
- export interface LanguageMap {
187
- /**
188
- * Get a defined language's definition.
189
- */
190
- [language: string]: Grammar;
191
- }
192
- export interface LanguageMapProtocol {
193
- /**
194
- * Creates a deep copy of the language with the given id and appends the given tokens.
195
- *
196
- * If a token in `redef` also appears in the copied language, then the existing token in the copied language
197
- * will be overwritten at its original position.
198
- *
199
- * @param id The id of the language to extend. This has to be a key in `Prism.languages`.
200
- * @param redef The new tokens to append.
201
- * @returns The new language created.
202
- * @example
203
- * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
204
- * 'color': /\b(?:red|green|blue)\b/
205
- * });
206
- */
207
- extend(id: string, redef: Grammar): Grammar;
208
-
209
- /**
210
- * Inserts tokens _before_ another token in a language definition or any other grammar.
211
- *
212
- * As this needs to recreate the object (we cannot actually insert before keys in object literals),
213
- * we cannot just provide an object, we need an object and a key.
214
- *
215
- * If the grammar of `inside` and `insert` have tokens with the same name, the tokens in `inside` will be ignored.
216
- *
217
- * All references of the old object accessible from `Prism.languages` or `insert` will be replace with the new one.
218
- *
219
- * @param inside The property of `root` that contains the object to be modified.
220
- *
221
- * This is usually a language id.
222
- * @param before The key to insert before.
223
- * @param insert An object containing the key-value pairs to be inserted.
224
- * @param [root] The object containing `inside`, i.e. the object that contains the object that will be modified.
225
- *
226
- * Defaults to `Prism.languages`.
227
- * @returns The new grammar created.
228
- * @example
229
- * Prism.languages.insertBefore('markup', 'cdata', {
230
- * 'style': { ... }
231
- * });
232
- */
233
- insertBefore(
234
- inside: string,
235
- before: string,
236
- insert: Grammar,
237
- root: LanguageMap
238
- ): Grammar;
239
- }
240
-
241
- export namespace hooks {
242
- /**
243
- * @param env The environment variables of the hook.
244
- */
245
- type HookCallback = (env: Environment) => void;
246
- type HookTypes = keyof HookEnvironmentMap;
247
-
248
- interface HookEnvironmentMap {
249
- "before-highlightall": RequiredEnvironment<"selector">;
250
-
251
- "before-sanity-check": ElementEnvironment;
252
- "before-highlight": ElementEnvironment;
253
-
254
- "before-insert": ElementHighlightedEnvironment;
255
- "after-highlight": ElementHighlightedEnvironment;
256
- complete: ElementHighlightedEnvironment;
257
-
258
- "before-tokenize": TokenizeEnvironment;
259
- "after-tokenize": TokenizeEnvironment;
260
-
261
- wrap: RequiredEnvironment<
262
- "type" | "content" | "tag" | "classes" | "attributes" | "language"
263
- >;
264
- }
265
-
266
- type RequiredEnvironment<
267
- T extends keyof Environment,
268
- U extends Environment = Environment
269
- > = U & Required<Pick<U, T>>;
270
- type ElementEnvironment = RequiredEnvironment<
271
- "element" | "language" | "grammar" | "code"
272
- >;
273
- type ElementHighlightedEnvironment = RequiredEnvironment<
274
- "highlightedCode",
275
- ElementEnvironment
276
- >;
277
- type TokenizeEnvironment = RequiredEnvironment<
278
- "code" | "grammar" | "language"
279
- >;
280
-
281
- interface RegisteredHooks {
282
- [hook: string]: HookCallback[];
283
- }
284
-
285
- const all: RegisteredHooks;
286
-
287
- /**
288
- * Adds the given callback to the list of callbacks for the given hook.
289
- *
290
- * The callback will be invoked when the hook it is registered for is run.
291
- * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
292
- *
293
- * One callback function can be registered to multiple hooks and the same hook multiple times.
294
- *
295
- * @param name The name of the hook.
296
- * @param callback The callback function which is given environment variables.
297
- */
298
- function add<K extends keyof HookEnvironmentMap>(
299
- name: K,
300
- callback: (env: HookEnvironmentMap[K]) => void
301
- ): void;
302
- function add(name: string, callback: HookCallback): void;
303
-
304
- /**
305
- * Runs a hook invoking all registered callbacks with the given environment variables.
306
- *
307
- * Callbacks will be invoked synchronously and in the order in which they were registered.
308
- *
309
- * @param name The name of the hook.
310
- * @param env The environment variables of the hook passed to all callbacks registered.
311
- */
312
- function run<K extends keyof HookEnvironmentMap>(
313
- name: K,
314
- env: HookEnvironmentMap[K]
315
- ): void;
316
- function run(name: string, env: Environment): void;
1
+ declare namespace PrismAlt {
2
+ export interface Grammar { }
3
+ export const languages: { [language: string]: Grammar; };
4
+ export const plugins: Record<string, {
5
+ setDefaults(cfg: Record<string, unknown>): void;
6
+ normalize(text: string, config?: unknown): string;
7
+ }>;
8
+ export function highlight(
9
+ text: string,
10
+ grammar: Grammar,
11
+ language: string
12
+ ): string;
317
13
  }
318
14
 
319
- export type TokenStream = string | Token | Array<string | Token>;
320
-
321
- export class Token {
322
- /**
323
- * Creates a new token.
324
- *
325
- * @param type See {@link Prism.Token#type type}
326
- * @param content See {@link Prism.Token#content content}
327
- * @param [alias] The alias(es) of the token.
328
- * @param [matchedStr=""] A copy of the full string this token was created from.
329
- * @param [greedy=false] See {@link Prism.Token#greedy greedy}
330
- */
331
- constructor(
332
- type: string,
333
- content: TokenStream,
334
- alias?: string | string[],
335
- matchedStr?: string,
336
- greedy?: boolean
337
- );
338
-
339
- /**
340
- * The type of the token.
341
- *
342
- * This is usually the key of a pattern in a {@link Grammar}.
343
- */
344
- type: string;
345
-
346
- /**
347
- * The strings or tokens contained by this token.
348
- *
349
- * This will be a token stream if the pattern matched also defined an `inside` grammar.
350
- */
351
- content: TokenStream;
352
-
353
- /**
354
- * The alias(es) of the token.
355
- *
356
- * @see TokenObject
357
- */
358
- alias: string | string[];
359
-
360
- /**
361
- * The length of the matched string or 0.
362
- */
363
- length: number;
364
-
365
- /**
366
- * Whether the pattern that created this token is greedy or not.
367
- *
368
- * @see TokenObject
369
- */
370
- greedy: boolean;
371
-
372
- /**
373
- * Converts the given token or token stream to an HTML representation.
374
- *
375
- * The following hooks will be run:
376
- * 1. `wrap`: On each {@link Prism.Token}.
377
- *
378
- * @param token The token or token stream to be converted.
379
- * @param language The name of current language.
380
- * @param [parent] The parent token stream, if any.
381
- * @return The HTML representation of the token or token stream.
382
- * @private
383
- */
384
- static stringify(
385
- token: TokenStream,
386
- language: string,
387
- parent?: Array<string | Token>
388
- ): string;
15
+ declare module "prismjs" {
16
+ export default PrismAlt;
389
17
  }
@@ -1,3 +1,5 @@
1
+ import { RootIndex, PackageUtil, path } from '@travetto/manifest';
2
+
1
3
  import { RenderContext } from './context';
2
4
  import { Html } from './html';
3
5
  import { Markdown } from './markdown';
@@ -29,20 +31,34 @@ export class RenderUtil {
29
31
  throw new Error(`Unknown renderer with format: ${fmt}`);
30
32
  }
31
33
 
34
+ const mod = RootIndex.getFromSource(file)?.import;
35
+
32
36
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
33
- const res = (await import(file)) as DocumentShape;
37
+ const res = await import(mod!) as DocumentShape;
34
38
 
35
39
  if (!this.#imported.has(file)) {
36
40
  this.#imported.set(file, {
37
41
  wrap: res.wrap,
38
42
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
39
- root: ('_type' in res.text ? res.text : await res.text()) as AllType
43
+ root: await res.text() as AllType
40
44
  });
41
45
  }
42
46
 
43
47
  const { wrap, root } = this.#imported.get(file)!;
44
48
 
45
- const ctx = new RenderContext(file);
49
+ const manifestPkg = PackageUtil.readPackage(RootIndex.getModule('@travetto/manifest')!.source);
50
+
51
+ const mf = RootIndex.manifest;
52
+
53
+ const pkg = PackageUtil.readPackage(mf.workspacePath);
54
+ const repoBaseUrl = pkg.travetto?.docBaseUrl ?? mf.mainPath;
55
+
56
+ const ctx = new RenderContext(
57
+ file,
58
+ path.resolve(pkg.travetto?.docRoot ?? mf.workspacePath),
59
+ repoBaseUrl,
60
+ repoBaseUrl.includes('travetto.github') ? repoBaseUrl : manifestPkg.travetto!.docBaseUrl!
61
+ );
46
62
  const content = renderers[fmt].render(root, ctx).replace(/\n{3,100}/msg, '\n\n').trim();
47
63
  const preamble = renderers[fmt].render(ctx.preamble, ctx);
48
64
  return `${preamble}\n${wrap?.[fmt]?.(content) ?? content}\n`;
package/src/types.ts CHANGED
@@ -10,7 +10,7 @@ export type Wrapper = Record<string, (c: string) => string>;
10
10
  * Document file shape
11
11
  */
12
12
  export interface DocumentShape<T extends DocNode = DocNode> {
13
- text: T | (() => (T | Promise<T>));
13
+ text: () => (T | Promise<T>);
14
14
  wrap?: Wrapper;
15
15
  }
16
16
 
@@ -27,17 +27,12 @@ export interface RenderContextShape {
27
27
  /**
28
28
  * Github root for project
29
29
  */
30
- gitBaseUrl: string;
30
+ baseUrl: string;
31
31
 
32
32
  /**
33
33
  * Github root for travetto framework
34
34
  */
35
- travettoGitBaseUrl: string;
36
-
37
- /**
38
- * Local folder root for git
39
- */
40
- gitFolder: string;
35
+ travettoBaseUrl: string;
41
36
 
42
37
  /**
43
38
  * Get table of contents
package/src/util/file.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { readFileSync } from 'fs';
2
- import * as path from 'path';
1
+ import { existsSync, readFileSync } from 'fs';
3
2
 
4
- import { FsUtil, Package, PathUtil } from '@travetto/boot';
3
+ import { path, RootIndex } from '@travetto/manifest';
5
4
 
6
5
  const ESLINT_PATTERN = /\s*\/\/ eslint.*$/;
7
6
 
@@ -23,12 +22,18 @@ export class FileUtil {
23
22
  * @param file
24
23
  * @returns
25
24
  */
26
- static resolveFile(file: string): { resolved: string, cleaned: string } {
27
- if (!FsUtil.existsSync(PathUtil.resolveUnix(file))) {
28
- file = require.resolve(file);
25
+ static resolveFile(file: string): string {
26
+ let resolved = path.resolve(file);
27
+ if (!existsSync(resolved)) {
28
+ if (file.endsWith('.ts')) {
29
+ resolved = RootIndex.resolveFileImport(file);
30
+ resolved = RootIndex.getSourceFile(resolved);
31
+ }
32
+ if (!existsSync(resolved)) {
33
+ throw new Error(`Unknown file to resolve: ${file}`);
34
+ }
29
35
  }
30
- const resolved = PathUtil.resolveUnix(file);
31
- return { resolved, cleaned: PathUtil.simplifyPath(resolved, Package.name) };
36
+ return resolved;
32
37
  }
33
38
 
34
39
  /**
@@ -38,15 +43,14 @@ export class FileUtil {
38
43
  * @returns
39
44
  */
40
45
  static read(file: string): { content: string, language: string, file: string } {
41
- const { resolved, cleaned } = this.resolveFile(file);
46
+ file = this.resolveFile(file);
42
47
 
43
- const ext = path.extname(resolved).replace(/^[.]/, '');
48
+ const ext = path.extname(file).replace(/^[.]/, '');
44
49
  const language = this.#extToLang[ext] ?? ext;
45
50
 
46
51
  let text: string | undefined;
47
52
  if (language) {
48
- text = readFileSync(resolved, 'utf8')
49
- .replace(/^\/\/\s*@with-module.*/, '');
53
+ text = readFileSync(file, 'utf8');
50
54
 
51
55
  text = text.split(/\n/)
52
56
  .map(x => {
@@ -59,21 +63,21 @@ export class FileUtil {
59
63
  .join('\n');
60
64
  }
61
65
 
62
- return { content: text ?? '', language, file: cleaned };
66
+ return { content: text ?? '', language, file };
63
67
  }
64
68
 
65
69
  /**
66
70
  * Determine if a file is a decorator
67
71
  */
68
72
  static isDecorator(name: string, file: string): boolean {
69
- const { resolved } = this.resolveFile(file);
73
+ file = this.resolveFile(file);
70
74
 
71
- const key = `${name}:${resolved}`;
75
+ const key = `${name}:${file}`;
72
76
  if (key in this.#decCache) {
73
77
  return this.#decCache[key];
74
78
  }
75
79
 
76
- const text = readFileSync(resolved, 'utf8')
80
+ const text = readFileSync(file, 'utf8')
77
81
  .split(/\n/g);
78
82
 
79
83
  const start = text.findIndex(x => new RegExp(`function ${name}\\b`).test(x));