ts-const-value-transformer 0.5.0 → 0.5.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.5.1
4
+
5
+ - Fix missing for handling `ignoreFiles` for `createTransformer` (used from ts-loader, etc.)
6
+
3
7
  ## v0.5.0
4
8
 
5
9
  - Add `useUndefinedSymbolForUndefinedValue` and `hoistUndefinedSymbol` options
package/README.md CHANGED
@@ -264,6 +264,8 @@ Prints (generates) source code from `SourceFile`, along with raw source-map data
264
264
 
265
265
  Transforms the source file with TypeScript project. You don't need to call this function directly; use `createTransformer` or `createPortalTransformer` instead.
266
266
 
267
+ Note that `ignoreFiles` of `options` will be ignored for this function.
268
+
267
269
  #### version: string
268
270
 
269
271
  The version string of this package.
@@ -2,24 +2,11 @@ import * as fs from 'fs';
2
2
  import { createRequire } from 'module';
3
3
  import * as path from 'path';
4
4
  import createTransformer from './createTransformer.mjs';
5
- import { printSourceWithMap } from './transform.mjs';
5
+ import { getIgnoreFilesFunction, printSourceWithMap, } from './transform.mjs';
6
6
  const require = createRequire(import.meta.url);
7
7
  function createPortalTransformerImpl(options, ts) {
8
8
  const project = options.project ?? 'tsconfig.json';
9
- let ignoreFiles = options.ignoreFiles ?? [];
10
- if (typeof ignoreFiles !== 'function') {
11
- const a = ignoreFiles;
12
- ignoreFiles = (fileName) => {
13
- return a.some((t) => {
14
- if (typeof t === 'string') {
15
- return fileName.indexOf(t) >= 0;
16
- }
17
- else {
18
- return t.test(fileName);
19
- }
20
- });
21
- };
22
- }
9
+ const ignoreFiles = getIgnoreFilesFunction(options.ignoreFiles);
23
10
  const cwd = options.cwd ?? process.cwd();
24
11
  const getCurrentDirectory = () => cwd;
25
12
  const config = ts.getParsedCommandLineOfConfigFile(project, void 0, {
@@ -1,15 +1,20 @@
1
- import { transformSource } from './transform.mjs';
1
+ import { getIgnoreFilesFunction, transformSource, } from './transform.mjs';
2
2
  export default function createTransformer(program,
3
3
  // for ttypescript and ts-patch
4
4
  config,
5
5
  // for ts-patch
6
6
  extras) {
7
+ const options = {
8
+ ...config?.options,
9
+ ...(extras?.ts && { ts: extras?.ts }),
10
+ };
11
+ const ignoreFiles = getIgnoreFilesFunction(options.ignoreFiles);
7
12
  return (context) => {
8
13
  return (sourceFile) => {
9
- return transformSource(sourceFile, program, context, {
10
- ...config?.options,
11
- ...(extras?.ts && { ts: extras?.ts }),
12
- });
14
+ if (ignoreFiles(sourceFile.fileName)) {
15
+ return sourceFile;
16
+ }
17
+ return transformSource(sourceFile, program, context, options);
13
18
  };
14
19
  };
15
20
  }
@@ -35,6 +35,7 @@ export interface TransformOptions {
35
35
  */
36
36
  ignoreFiles?: ReadonlyArray<string | RegExp> | ((fileName: string) => boolean);
37
37
  }
38
+ export declare function getIgnoreFilesFunction(ignoreFiles: TransformOptions['ignoreFiles']): (fileName: string) => boolean;
38
39
  export declare function transformSource(sourceFile: ts.SourceFile, program: ts.Program, context: ts.TransformationContext, options?: TransformOptions): ts.SourceFile;
39
40
  export declare function printSource(sourceFile: ts.SourceFile): string;
40
41
  export declare function printSourceWithMap(sourceFile: ts.SourceFile, originalSourceName: string, startOfSourceMap?: sourceMap.RawSourceMap): [string, sourceMap.RawSourceMap];
@@ -19,6 +19,26 @@ function assignDefaultValues(options = {}) {
19
19
  };
20
20
  }
21
21
  ////////////////////////////////////////////////////////////////////////////////
22
+ export function getIgnoreFilesFunction(ignoreFiles) {
23
+ if (!ignoreFiles) {
24
+ return () => false;
25
+ }
26
+ if (typeof ignoreFiles === 'function') {
27
+ return ignoreFiles;
28
+ }
29
+ const a = ignoreFiles;
30
+ return (fileName) => {
31
+ return a.some((t) => {
32
+ if (typeof t === 'string') {
33
+ return fileName.indexOf(t) >= 0;
34
+ }
35
+ else {
36
+ return t.test(fileName);
37
+ }
38
+ });
39
+ };
40
+ }
41
+ ////////////////////////////////////////////////////////////////////////////////
22
42
  export function transformSource(sourceFile, program, context, options) {
23
43
  return visitNodeChildren(sourceFile, sourceFile, sourceFile, program, context, assignDefaultValues(options));
24
44
  }
@@ -1,2 +1,2 @@
1
- declare const _default: "0.5.0";
1
+ declare const _default: "0.5.1";
2
2
  export default _default;
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export default '0.5.0';
1
+ export default '0.5.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-const-value-transformer",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "engines": {
5
5
  "node": ">=20.19.3"
6
6
  },