@augment-vir/node 31.12.0 → 31.14.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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* node:coverage disable */
|
|
2
|
+
/**
|
|
3
|
+
* This script is used to replace all `/src/` imports with `/dist/`. This is used for making a
|
|
4
|
+
* compiled, but not bundled (because that would affect relative file path variables), backend
|
|
5
|
+
* mono-repo be able to run without `tsx`. (Because `tsx` uses a lot more memory than plain
|
|
6
|
+
* `node`.)
|
|
7
|
+
*
|
|
8
|
+
* To use this script properly, call it after compiling your backend. It should be run from your
|
|
9
|
+
* mono-repo root. Like this:
|
|
10
|
+
*
|
|
11
|
+
* ```json
|
|
12
|
+
* {
|
|
13
|
+
* "scripts": {
|
|
14
|
+
* "build:backend": "npm run compile && npx tsx node_modules/@augment-vir/node/src/scripts/fix-src-imports.script.ts"
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import { assert, check } from '@augment-vir/assert';
|
|
20
|
+
import { filterMap, log } from '@augment-vir/common';
|
|
21
|
+
import { joinFilesToDir, readJsonFile, runShellCommand, writeJsonFile } from '@augment-vir/node';
|
|
22
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
23
|
+
import { join, relative } from 'node:path';
|
|
24
|
+
import { queryNpmWorkspace } from '../augments/npm/query-workspace.js';
|
|
25
|
+
const propertiesToReplace = [
|
|
26
|
+
'main',
|
|
27
|
+
'module',
|
|
28
|
+
];
|
|
29
|
+
async function findFilesThatNeedImportFixes(monoRepoPath) {
|
|
30
|
+
const { stdout } = await runShellCommand('find . -type d -name "node_modules" -prune -o -type f -path "*/dist/*.js" -exec grep -lE "from \'.*?/src/.*?\';" {} +', {
|
|
31
|
+
rejectOnError: true,
|
|
32
|
+
cwd: monoRepoPath,
|
|
33
|
+
});
|
|
34
|
+
const files = filterMap(stdout.trim().split('\n'), (line) => line.trim(), check.isTruthy);
|
|
35
|
+
return joinFilesToDir(monoRepoPath, files);
|
|
36
|
+
}
|
|
37
|
+
async function updateAllPackageJsonPaths(monoRepoPath) {
|
|
38
|
+
const workspaces = await queryNpmWorkspace(monoRepoPath);
|
|
39
|
+
await Promise.all(workspaces.map(async (workspace) => {
|
|
40
|
+
const packageJsonPath = join(workspace.path, 'package.json');
|
|
41
|
+
const packageJson = (await readJsonFile(packageJsonPath));
|
|
42
|
+
assert.isObject(packageJson);
|
|
43
|
+
let modified = false;
|
|
44
|
+
propertiesToReplace.forEach((property) => {
|
|
45
|
+
if (property in packageJson && check.isString(packageJson[property])) {
|
|
46
|
+
modified = true;
|
|
47
|
+
packageJson[property] = packageJson[property]
|
|
48
|
+
.replace('src/', 'dist/')
|
|
49
|
+
.replace('.ts', '.js');
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (modified) {
|
|
53
|
+
await writeJsonFile(packageJsonPath, packageJson);
|
|
54
|
+
log.faint(`Updated ${relative(monoRepoPath, packageJsonPath)}`);
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
async function fixAllSrcImports(monoRepoPath) {
|
|
59
|
+
const filePaths = await findFilesThatNeedImportFixes(monoRepoPath);
|
|
60
|
+
await Promise.all(filePaths.map(async (filePath) => {
|
|
61
|
+
const contents = String(await readFile(filePath));
|
|
62
|
+
const fixedContents = contents.replaceAll(/(from ["'][^'"]+?)\/src\/([^'"]+)['"];/g, "$1/dist/$2';");
|
|
63
|
+
await writeFile(filePath, fixedContents);
|
|
64
|
+
log.faint(`Fixed imports in ${relative(monoRepoPath, filePath)}`);
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
async function fixAll(monoRepoPath) {
|
|
68
|
+
await Promise.all([
|
|
69
|
+
updateAllPackageJsonPaths(monoRepoPath),
|
|
70
|
+
fixAllSrcImports(monoRepoPath),
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
await fixAll(process.cwd());
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/* node:coverage disable */
|
|
2
2
|
/**
|
|
3
|
+
* This script is used to replace `node_modules/.bin` files so that they run with typescript. This
|
|
4
|
+
* is used in dev for packages that are dependencies of the listed packages (in `packagesToFix`),
|
|
5
|
+
* such as `augment-vir` itself.
|
|
6
|
+
*
|
|
3
7
|
* To use this script properly, call it directly in your postinstall script. Like this:
|
|
4
8
|
*
|
|
5
9
|
* ```json
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/node",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.14.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"test:update": "npm test"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@augment-vir/assert": "^31.
|
|
42
|
-
"@augment-vir/common": "^31.
|
|
41
|
+
"@augment-vir/assert": "^31.14.0",
|
|
42
|
+
"@augment-vir/common": "^31.14.0",
|
|
43
43
|
"@date-vir/duration": "^7.3.1",
|
|
44
44
|
"ansi-styles": "^6.2.1",
|
|
45
45
|
"terminate": "^2.8.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"typed-event-target": "^4.0.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@augment-vir/test": "^31.
|
|
51
|
+
"@augment-vir/test": "^31.14.0",
|
|
52
52
|
"@prisma/client": "^6.6.0",
|
|
53
53
|
"@types/node": "^22.14.1",
|
|
54
54
|
"@web/dev-server-esbuild": "^1.0.4",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* node:coverage disable */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This script is used to replace all `/src/` imports with `/dist/`. This is used for making a
|
|
5
|
+
* compiled, but not bundled (because that would affect relative file path variables), backend
|
|
6
|
+
* mono-repo be able to run without `tsx`. (Because `tsx` uses a lot more memory than plain
|
|
7
|
+
* `node`.)
|
|
8
|
+
*
|
|
9
|
+
* To use this script properly, call it after compiling your backend. It should be run from your
|
|
10
|
+
* mono-repo root. Like this:
|
|
11
|
+
*
|
|
12
|
+
* ```json
|
|
13
|
+
* {
|
|
14
|
+
* "scripts": {
|
|
15
|
+
* "build:backend": "npm run compile && npx tsx node_modules/@augment-vir/node/src/scripts/fix-src-imports.script.ts"
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {assert, check} from '@augment-vir/assert';
|
|
22
|
+
import {filterMap, log, type JsonCompatibleObject} from '@augment-vir/common';
|
|
23
|
+
import {joinFilesToDir, readJsonFile, runShellCommand, writeJsonFile} from '@augment-vir/node';
|
|
24
|
+
import {readFile, writeFile} from 'node:fs/promises';
|
|
25
|
+
import {join, relative} from 'node:path';
|
|
26
|
+
import {queryNpmWorkspace} from '../augments/npm/query-workspace.js';
|
|
27
|
+
|
|
28
|
+
const propertiesToReplace = [
|
|
29
|
+
'main',
|
|
30
|
+
'module',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
async function findFilesThatNeedImportFixes(monoRepoPath: string) {
|
|
34
|
+
const {stdout} = await runShellCommand(
|
|
35
|
+
'find . -type d -name "node_modules" -prune -o -type f -path "*/dist/*.js" -exec grep -lE "from \'.*?/src/.*?\';" {} +',
|
|
36
|
+
{
|
|
37
|
+
rejectOnError: true,
|
|
38
|
+
cwd: monoRepoPath,
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const files = filterMap(stdout.trim().split('\n'), (line) => line.trim(), check.isTruthy);
|
|
43
|
+
|
|
44
|
+
return joinFilesToDir(monoRepoPath, files);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function updateAllPackageJsonPaths(monoRepoPath: string) {
|
|
48
|
+
const workspaces = await queryNpmWorkspace(monoRepoPath);
|
|
49
|
+
|
|
50
|
+
await Promise.all(
|
|
51
|
+
workspaces.map(async (workspace) => {
|
|
52
|
+
const packageJsonPath = join(workspace.path, 'package.json');
|
|
53
|
+
const packageJson = (await readJsonFile(packageJsonPath)) as unknown;
|
|
54
|
+
|
|
55
|
+
assert.isObject(packageJson);
|
|
56
|
+
let modified = false as boolean;
|
|
57
|
+
|
|
58
|
+
propertiesToReplace.forEach((property) => {
|
|
59
|
+
if (property in packageJson && check.isString(packageJson[property])) {
|
|
60
|
+
modified = true;
|
|
61
|
+
packageJson[property] = packageJson[property]
|
|
62
|
+
.replace('src/', 'dist/')
|
|
63
|
+
.replace('.ts', '.js');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (modified) {
|
|
68
|
+
await writeJsonFile(packageJsonPath, packageJson as JsonCompatibleObject);
|
|
69
|
+
log.faint(`Updated ${relative(monoRepoPath, packageJsonPath)}`);
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function fixAllSrcImports(monoRepoPath: string) {
|
|
76
|
+
const filePaths = await findFilesThatNeedImportFixes(monoRepoPath);
|
|
77
|
+
|
|
78
|
+
await Promise.all(
|
|
79
|
+
filePaths.map(async (filePath) => {
|
|
80
|
+
const contents = String(await readFile(filePath));
|
|
81
|
+
const fixedContents = contents.replaceAll(
|
|
82
|
+
/(from ["'][^'"]+?)\/src\/([^'"]+)['"];/g,
|
|
83
|
+
"$1/dist/$2';",
|
|
84
|
+
);
|
|
85
|
+
await writeFile(filePath, fixedContents);
|
|
86
|
+
log.faint(`Fixed imports in ${relative(monoRepoPath, filePath)}`);
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function fixAll(monoRepoPath: string) {
|
|
92
|
+
await Promise.all([
|
|
93
|
+
updateAllPackageJsonPaths(monoRepoPath),
|
|
94
|
+
fixAllSrcImports(monoRepoPath),
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
await fixAll(process.cwd());
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/* node:coverage disable */
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
+
* This script is used to replace `node_modules/.bin` files so that they run with typescript. This
|
|
5
|
+
* is used in dev for packages that are dependencies of the listed packages (in `packagesToFix`),
|
|
6
|
+
* such as `augment-vir` itself.
|
|
7
|
+
*
|
|
4
8
|
* To use this script properly, call it directly in your postinstall script. Like this:
|
|
5
9
|
*
|
|
6
10
|
* ```json
|