@dungarees/transpile 0.11.6 → 0.12.0

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/package.json CHANGED
@@ -7,20 +7,16 @@
7
7
  "dependencies": {
8
8
  "@dungarees/fs": "*",
9
9
  "@dungarees/rxjs": "*",
10
- "rxjs": "^7.8.1"
10
+ "rxjs": "^7.8.1",
11
+ "typescript": "^5.9.3"
11
12
  },
12
13
  "devDependencies": {
13
- "typescript": "^5.9.3",
14
14
  "vitest": "^3.0.2"
15
15
  },
16
16
  "author": "info@productkind.com",
17
17
  "license": "MIT",
18
- "version": "0.11.6",
18
+ "version": "0.12.0",
19
19
  "exports": {
20
- "./service.test.ts": {
21
- "import": "./service.test.js",
22
- "types": "./service.test.d.ts"
23
- },
24
20
  "./service.ts": {
25
21
  "import": "./service.js",
26
22
  "types": "./service.d.ts"
package/service.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import type { FileSystemService } from '@dungarees/fs/service.ts';
2
2
  import type { Observable } from 'rxjs';
3
- type Transpiler = {
3
+ export type Transpiler = {
4
4
  transpileDir: (options: {
5
5
  input: string;
6
6
  output: string;
7
+ exclude?: (filePath: string) => boolean;
7
8
  }) => Observable<TranspileDirOutput[]>;
8
9
  };
9
10
  export type TranspileDirOutput = {
@@ -11,5 +12,4 @@ export type TranspileDirOutput = {
11
12
  output: string;
12
13
  type: string;
13
14
  };
14
- export declare const createTranspilerService: (fileSystem: FileSystemService) => Transpiler;
15
- export {};
15
+ export declare const createTranspiler: (fileSystem: FileSystemService) => Transpiler;
package/service.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { asyncFunctionToObservable } from '@dungarees/rxjs/util.ts';
2
2
  import path from 'node:path';
3
3
  import ts from 'typescript';
4
- export const createTranspilerService = (fileSystem) => {
5
- const transpileDirAsync = async ({ input, output, }) => {
6
- const tsFiles = await fileSystem.globAsync(path.join(input, '**', '*.ts'));
4
+ const isOutsideNodeModules = (filePath) => !filePath.split('/').includes('node_modules');
5
+ export const createTranspiler = (fileSystem) => {
6
+ const transpileDirAsync = async ({ input, output, exclude = () => false, }) => {
7
+ const tsFiles = (await fileSystem.globAsync(path.join(input, '**', '*.ts'))).filter((filePath) => isOutsideNodeModules(filePath) && !exclude(filePath));
7
8
  const pathAndContentPairs = Object.entries(await fileSystem.readBulkAsync(tsFiles));
8
9
  const sources = new Map(pathAndContentPairs);
9
10
  const compilerOptions = {
package/service.test.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/service.test.js DELETED
@@ -1,48 +0,0 @@
1
- import { createTranspilerService } from './service.js';
2
- import { createFakeFileSystem } from '@dungarees/fs/fake.ts';
3
- import { lastValueFrom } from 'rxjs';
4
- import { expect, test } from 'vitest';
5
- const srcDirFile1 = `
6
- import { assertDefined } from '@dungarees/core/utils.ts';
7
-
8
- export const fun1 = (input: string): string => {
9
- return assertDefined(input + ' from file1');
10
- };
11
- `;
12
- const srcDirFile2 = `
13
- import { fun1 } from './file1.ts';
14
-
15
- export const fun2 = (input: string): string => {
16
- return fun1(input + ' and file2');
17
- };
18
- `;
19
- const srcDirFile3 = `
20
- console.log('File 3');
21
- `;
22
- test('transpile should transpile a directory', async () => {
23
- const fs = createFakeFileSystem({
24
- '/src-dir/file1.ts': srcDirFile1.trim(),
25
- '/src-dir/file2.ts': srcDirFile2.trim(),
26
- '/src-dir/sub-dir/file3.ts': srcDirFile3.trim(),
27
- });
28
- const transpileService = createTranspilerService(fs);
29
- const files = await lastValueFrom(transpileService.transpileDir({
30
- input: '/src-dir',
31
- output: '/dist-dir',
32
- }));
33
- expect(fs.readFileSync('/dist-dir/file1.js', 'utf-8')).toBe("import { assertDefined } from '@dungarees/core/utils.ts';\nexport const fun1 = (input) => {\n return assertDefined(input + ' from file1');\n};\n");
34
- expect(fs.readFileSync('/dist-dir/file1.d.ts', 'utf-8')).toBe('export declare const fun1: (input: string) => string;\n');
35
- expect(fs.readFileSync('/dist-dir/file2.js', 'utf-8')).toBe("import { fun1 } from './file1.js';\nexport const fun2 = (input) => {\n return fun1(input + ' and file2');\n};\n");
36
- expect(fs.readFileSync('/dist-dir/file2.d.ts', 'utf-8')).toBe('export declare const fun2: (input: string) => string;\n');
37
- expect(fs.readFileSync('/dist-dir/sub-dir/file3.js', 'utf-8')).toBe("console.log('File 3');\n");
38
- expect(fs.readFileSync('/dist-dir/sub-dir/file3.d.ts', 'utf-8')).toBe('');
39
- expect(files).toEqual([
40
- { input: '/src-dir/file1.ts', output: '/dist-dir/file1.js', type: '/dist-dir/file1.d.ts' },
41
- { input: '/src-dir/file2.ts', output: '/dist-dir/file2.js', type: '/dist-dir/file2.d.ts' },
42
- {
43
- input: '/src-dir/sub-dir/file3.ts',
44
- output: '/dist-dir/sub-dir/file3.js',
45
- type: '/dist-dir/sub-dir/file3.d.ts',
46
- },
47
- ]);
48
- });