@awesomeness-js/utils 1.2.12 → 1.2.13

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomeness-js/utils",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
package/src/build.js CHANGED
@@ -25,6 +25,7 @@ async function build({
25
25
 
26
26
  const gen = () => generateFile({
27
27
  src,
28
+ dest,
28
29
  exportRoots,
29
30
  ignore,
30
31
  includeComments,
@@ -7,6 +7,7 @@ import generateNamedExports from './generateNamedExports.js';
7
7
 
8
8
  export default function generateFile({
9
9
  src,
10
+ dest,
10
11
  exportRoots,
11
12
  ignore,
12
13
  includeComments,
@@ -32,7 +33,8 @@ export default function generateFile({
32
33
  const importStatements = generateImportStatements({
33
34
  fileDataList,
34
35
  dts,
35
- src
36
+ src,
37
+ dest
36
38
  });
37
39
 
38
40
  const flatExportLines = generateFlatExportLines({
@@ -1,18 +1,36 @@
1
+ import { dirname, relative } from 'path';
2
+
1
3
  export default function generateImportStatements({
2
4
  fileDataList,
3
5
  dts,
4
- src
6
+ src,
7
+ dest
5
8
  }) {
6
9
 
7
10
  let statements = '';
11
+ const destDir = dirname(dest);
8
12
 
9
13
  fileDataList.forEach(({
10
14
  importVarName, importPath
11
15
  }) => {
12
16
 
13
- statements += dts
14
- ? `import type ${importVarName} from '.${importPath.replace(src,'')}';\n`
15
- : `import ${importVarName} from '${importPath}.js';\n`;
17
+ if (dts) {
18
+
19
+ const normalizedDtsPath = `.${importPath.replace(src, '')}`.replace(/\\/g, '/');
20
+
21
+ statements += `import type ${importVarName} from '${normalizedDtsPath}';\n`;
22
+
23
+ return;
24
+
25
+ }
26
+
27
+ const targetPath = `${importPath}.js`;
28
+ const normalizedRelativePath = relative(destDir, targetPath).replace(/\\/g, '/');
29
+ const importSpecifier = normalizedRelativePath.startsWith('.')
30
+ ? normalizedRelativePath
31
+ : `./${normalizedRelativePath}`;
32
+
33
+ statements += `import ${importVarName} from '${importSpecifier}';\n`;
16
34
 
17
35
  });
18
36
 
@@ -0,0 +1 @@
1
+ export default () => true;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file is auto-generated by the build script.
3
+ * It consolidates API functions for use in the application.
4
+ * Do not edit manually.
5
+ */
6
+ import _hello from '../../src/hello.js';
7
+
8
+ export { _hello as hello };
9
+
10
+
11
+ export default {
12
+ hello: _hello,
13
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * This file is auto-generated by the build script.
3
+ * It consolidates API functions for use in the application.
4
+ * Do not edit manually.
5
+ */
6
+ import _user_bibleVersion from './functions/user/bibleVersion.js';
7
+
8
+
9
+ export const user = {
10
+ bibleVersion: _user_bibleVersion
11
+ };
12
+
13
+
14
+ export default {
15
+ user: {
16
+ bibleVersion: _user_bibleVersion,
17
+ },
18
+ };
@@ -0,0 +1 @@
1
+ export default () => true;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file is auto-generated by the build script.
3
+ * It consolidates API functions for use in the application.
4
+ * Do not edit manually.
5
+ */
6
+ import _hello from '../src/hello.js';
7
+
8
+ export { _hello as hello };
9
+
10
+
11
+ export default {
12
+ hello: _hello,
13
+ };
@@ -0,0 +1,104 @@
1
+ import { expect, test } from 'vitest';
2
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
3
+ import { dirname, join } from 'path';
4
+ import utils from '../index.js';
5
+
6
+ function writeJs(filePath, content = 'export default () => true;\n') {
7
+
8
+ mkdirSync(dirname(filePath), {
9
+ recursive: true
10
+ });
11
+ writeFileSync(filePath, content);
12
+
13
+ }
14
+
15
+ test('build generates imports relative to nested destination', async () => {
16
+
17
+ const root = join('test', 'buildSpotCheck', 'nested');
18
+
19
+ rmSync(root, {
20
+ recursive: true,
21
+ force: true
22
+ });
23
+
24
+ const src = join(root, 'sites', 'abetterbibleapp.com', 'api', 'functions');
25
+ const dest = join(root, 'sites', 'abetterbibleapp.com', 'api', 'app.js');
26
+ const functionFile = join(src, 'user', 'bibleVersion.js');
27
+
28
+ writeJs(functionFile);
29
+
30
+ await utils.build({
31
+ src,
32
+ dest,
33
+ dts: false,
34
+ ignore: [
35
+ '*.test.js'
36
+ ]
37
+ });
38
+
39
+ const output = readFileSync(dest, 'utf8');
40
+
41
+ expect(output).toContain("import _user_bibleVersion from './functions/user/bibleVersion.js';");
42
+ expect(output).not.toContain("./sites/abetterbibleapp.com/api/functions/user/bibleVersion.js");
43
+
44
+ });
45
+
46
+ test('build generates correct imports for non-root destination', async () => {
47
+
48
+ const root = join('test', 'buildSpotCheck', 'nonRoot');
49
+
50
+ rmSync(root, {
51
+ recursive: true,
52
+ force: true
53
+ });
54
+
55
+ const src = join(root, 'src');
56
+ const dest = join(root, 'test', 'justATest.js');
57
+ const functionFile = join(src, 'hello.js');
58
+
59
+ writeJs(functionFile);
60
+ mkdirSync(dirname(dest), {
61
+ recursive: true
62
+ });
63
+
64
+ await utils.build({
65
+ src,
66
+ dest,
67
+ dts: false
68
+ });
69
+
70
+ const output = readFileSync(dest, 'utf8');
71
+
72
+ expect(output).toContain("import _hello from '../src/hello.js';");
73
+
74
+ });
75
+
76
+ test('build generates correct imports for deeper non-root destination', async () => {
77
+
78
+ const root = join('test', 'buildSpotCheck', 'deeperNonRoot');
79
+
80
+ rmSync(root, {
81
+ recursive: true,
82
+ force: true
83
+ });
84
+
85
+ const src = join(root, 'src');
86
+ const dest = join(root, 'test', 'nested', 'justATest.js');
87
+ const functionFile = join(src, 'hello.js');
88
+
89
+ writeJs(functionFile);
90
+ mkdirSync(dirname(dest), {
91
+ recursive: true
92
+ });
93
+
94
+ await utils.build({
95
+ src,
96
+ dest,
97
+ dts: false
98
+ });
99
+
100
+ const output = readFileSync(dest, 'utf8');
101
+
102
+ expect(output).toContain("import _hello from '../../src/hello.js';");
103
+
104
+ });
@@ -1,5 +1,6 @@
1
- export default function generateFile({ src, exportRoots, ignore, includeComments, dts, useTabs }: {
1
+ export default function generateFile({ src, dest, exportRoots, ignore, includeComments, dts, useTabs }: {
2
2
  src: any;
3
+ dest: any;
3
4
  exportRoots: any;
4
5
  ignore: any;
5
6
  includeComments: any;
@@ -1,5 +1,6 @@
1
- export default function generateImportStatements({ fileDataList, dts, src }: {
1
+ export default function generateImportStatements({ fileDataList, dts, src, dest }: {
2
2
  fileDataList: any;
3
3
  dts: any;
4
4
  src: any;
5
+ dest: any;
5
6
  }): string;