@8ms/helpers 2.3.4 → 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 +76 -34
- package/.yarn/install-state.gz +0 -0
- package/package.json +1 -1
|
@@ -3,13 +3,18 @@ import fs from 'fs';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import {fileURLToPath} from 'url';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const srcRoot = path.join(projectRoot, 'src');
|
|
9
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
10
8
|
|
|
11
|
-
const
|
|
9
|
+
const projectRoot = path.join(__dirname, '..');
|
|
10
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
11
|
+
const srcRoot = path.join(projectRoot, 'src');
|
|
12
12
|
|
|
13
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
14
|
+
|
|
15
|
+
const excludeDirs = ['node_modules', 'scripts', 'jest', '.git', '.github', '.idea', 'tests', 'test'];
|
|
16
|
+
|
|
17
|
+
// Build exports object
|
|
13
18
|
const exports = {
|
|
14
19
|
'.': {
|
|
15
20
|
types: './index.d.ts',
|
|
@@ -19,51 +24,88 @@ const exports = {
|
|
|
19
24
|
}
|
|
20
25
|
};
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function scan(baseDir, relativePath = '')
|
|
27
|
+
// Fix ESM exports in a src index.ts file by appending .js to bare relative imports
|
|
28
|
+
function fixIndexFile(filePath)
|
|
25
29
|
{
|
|
26
|
-
|
|
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)
|
|
27
38
|
{
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
fs.writeFileSync(filePath, updated, 'utf8');
|
|
40
|
+
console.log(`Fixed: ${path.relative(projectRoot, filePath)}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
30
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
|
+
{
|
|
31
51
|
if(entry.isDirectory())
|
|
32
52
|
{
|
|
33
|
-
if(excludeDirs.
|
|
34
|
-
|
|
35
|
-
if(fs.existsSync(path.join(fullPath, 'index.js')))
|
|
53
|
+
if(!excludeDirs.includes(entry.name) && !entry.name.startsWith('.'))
|
|
36
54
|
{
|
|
37
|
-
|
|
38
|
-
const config = {types: `./${newRelativePath}/index.d.ts`, import: jsPath, require: jsPath, default: jsPath};
|
|
39
|
-
|
|
40
|
-
exports[`./${newRelativePath}`] = config;
|
|
41
|
-
exports[`./${newRelativePath}/index.js`] = config;
|
|
42
|
-
exports[`./${newRelativePath}/index.d.ts`] = {types: config.types, default: config.types};
|
|
55
|
+
fixSrcIndexFiles(path.join(dir, entry.name));
|
|
43
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)
|
|
66
|
+
function findIndexDirs(baseDir, relativePath = '')
|
|
67
|
+
{
|
|
68
|
+
const entries = fs.readdirSync(baseDir, {withFileTypes: true});
|
|
44
69
|
|
|
45
|
-
|
|
70
|
+
for(const entry of entries)
|
|
71
|
+
{
|
|
72
|
+
if(!entry.isDirectory() || excludeDirs.includes(entry.name) || entry.name.startsWith('.'))
|
|
73
|
+
{
|
|
74
|
+
continue;
|
|
46
75
|
}
|
|
47
|
-
|
|
76
|
+
|
|
77
|
+
const fullPath = path.join(baseDir, entry.name);
|
|
78
|
+
const newRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
79
|
+
const indexJsPath = path.join(fullPath, 'index.js');
|
|
80
|
+
|
|
81
|
+
if(fs.existsSync(indexJsPath))
|
|
48
82
|
{
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
83
|
+
const exportConfig = {
|
|
84
|
+
types: `./${newRelativePath}/index.d.ts`,
|
|
85
|
+
import: `./${newRelativePath}/index.js`,
|
|
86
|
+
require: `./${newRelativePath}/index.js`,
|
|
87
|
+
default: `./${newRelativePath}/index.js`
|
|
88
|
+
};
|
|
53
89
|
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
90
|
+
exports[`./${newRelativePath}`] = exportConfig;
|
|
91
|
+
exports[`./${newRelativePath}/index.js`] = exportConfig;
|
|
92
|
+
|
|
93
|
+
exports[`./${newRelativePath}/index.d.ts`] = {
|
|
94
|
+
types: `./${newRelativePath}/index.d.ts`,
|
|
95
|
+
default: `./${newRelativePath}/index.d.ts`
|
|
96
|
+
};
|
|
59
97
|
}
|
|
98
|
+
|
|
99
|
+
findIndexDirs(fullPath, newRelativePath);
|
|
60
100
|
}
|
|
61
101
|
}
|
|
62
102
|
|
|
63
|
-
|
|
64
|
-
|
|
103
|
+
fixSrcIndexFiles(srcRoot);
|
|
104
|
+
|
|
105
|
+
findIndexDirs(projectRoot);
|
|
65
106
|
|
|
66
107
|
packageJson.exports = exports;
|
|
67
|
-
|
|
108
|
+
|
|
109
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, '\t') + '\n', 'utf8');
|
|
68
110
|
|
|
69
111
|
console.log(`Generated exports for ${Object.keys(exports).length} entries`);
|
package/.yarn/install-state.gz
CHANGED
|
Binary file
|