@8ms/helpers 2.3.3 → 2.3.5
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/.github/generate-exports.js +46 -13
- package/.yarn/install-state.gz +0 -0
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import fs from 'fs';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import {fileURLToPath} from 'url';
|
|
@@ -7,12 +8,11 @@ const __dirname = path.dirname(__filename);
|
|
|
7
8
|
|
|
8
9
|
const projectRoot = path.join(__dirname, '..');
|
|
9
10
|
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
11
|
+
const srcRoot = path.join(projectRoot, 'src');
|
|
10
12
|
|
|
11
|
-
// Read package.json
|
|
12
13
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
const excludeDirs = ['node_modules', 'scripts', 'jest', 'src', '.git', '.github', '.idea'];
|
|
15
|
+
const excludeDirs = ['node_modules', 'scripts', 'jest', '.git', '.github', '.idea', 'tests', 'test'];
|
|
16
16
|
|
|
17
17
|
// Build exports object
|
|
18
18
|
const exports = {
|
|
@@ -24,7 +24,45 @@ const exports = {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
//
|
|
27
|
+
// Fix ESM exports in a src index.ts file by appending .js to bare relative imports
|
|
28
|
+
function fixIndexFile(filePath)
|
|
29
|
+
{
|
|
30
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
31
|
+
|
|
32
|
+
const updated = content.replace(
|
|
33
|
+
/^(export \* from ["'])(\.\/[^"'.]+)(["'];?)$/gm,
|
|
34
|
+
(_, prefix, specifier, suffix) => `${prefix}${specifier}.js${suffix}`
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if(updated !== content)
|
|
38
|
+
{
|
|
39
|
+
fs.writeFileSync(filePath, updated, 'utf8');
|
|
40
|
+
console.log(`Fixed: ${path.relative(projectRoot, filePath)}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Recursively scan src for index.ts files to fix
|
|
45
|
+
function fixSrcIndexFiles(dir)
|
|
46
|
+
{
|
|
47
|
+
const entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
48
|
+
|
|
49
|
+
for(const entry of entries)
|
|
50
|
+
{
|
|
51
|
+
if(entry.isDirectory())
|
|
52
|
+
{
|
|
53
|
+
if(!excludeDirs.includes(entry.name) && !entry.name.startsWith('.'))
|
|
54
|
+
{
|
|
55
|
+
fixSrcIndexFiles(path.join(dir, entry.name));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if(entry.name === 'index.ts')
|
|
59
|
+
{
|
|
60
|
+
fixIndexFile(path.join(dir, entry.name));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Recursively find all compiled directories with index.js files (outside src)
|
|
28
66
|
function findIndexDirs(baseDir, relativePath = '')
|
|
29
67
|
{
|
|
30
68
|
const entries = fs.readdirSync(baseDir, {withFileTypes: true});
|
|
@@ -36,11 +74,10 @@ function findIndexDirs(baseDir, relativePath = '')
|
|
|
36
74
|
continue;
|
|
37
75
|
}
|
|
38
76
|
|
|
39
|
-
const fullPath
|
|
77
|
+
const fullPath = path.join(baseDir, entry.name);
|
|
40
78
|
const newRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
41
|
-
const indexJsPath
|
|
79
|
+
const indexJsPath = path.join(fullPath, 'index.js');
|
|
42
80
|
|
|
43
|
-
// If this directory has an index.js, add it to exports
|
|
44
81
|
if(fs.existsSync(indexJsPath))
|
|
45
82
|
{
|
|
46
83
|
const exportConfig = {
|
|
@@ -50,29 +87,25 @@ function findIndexDirs(baseDir, relativePath = '')
|
|
|
50
87
|
default: `./${newRelativePath}/index.js`
|
|
51
88
|
};
|
|
52
89
|
|
|
53
|
-
// Add both the directory path and explicit index.js path
|
|
54
90
|
exports[`./${newRelativePath}`] = exportConfig;
|
|
55
91
|
exports[`./${newRelativePath}/index.js`] = exportConfig;
|
|
56
92
|
|
|
57
|
-
// Also add .d.ts mapping for TypeScript
|
|
58
93
|
exports[`./${newRelativePath}/index.d.ts`] = {
|
|
59
94
|
types: `./${newRelativePath}/index.d.ts`,
|
|
60
95
|
default: `./${newRelativePath}/index.d.ts`
|
|
61
96
|
};
|
|
62
97
|
}
|
|
63
98
|
|
|
64
|
-
// Recursively scan subdirectories
|
|
65
99
|
findIndexDirs(fullPath, newRelativePath);
|
|
66
100
|
}
|
|
67
101
|
}
|
|
68
102
|
|
|
69
|
-
|
|
103
|
+
fixSrcIndexFiles(srcRoot);
|
|
104
|
+
|
|
70
105
|
findIndexDirs(projectRoot);
|
|
71
106
|
|
|
72
|
-
// Update package.json with new exports
|
|
73
107
|
packageJson.exports = exports;
|
|
74
108
|
|
|
75
|
-
// Write back to package.json
|
|
76
109
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, '\t') + '\n', 'utf8');
|
|
77
110
|
|
|
78
111
|
console.log(`Generated exports for ${Object.keys(exports).length} entries`);
|
package/.yarn/install-state.gz
CHANGED
|
Binary file
|