@8ms/helpers 2.3.3 → 2.3.4
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 +39 -48
- package/.yarn/install-state.gz +0 -0
- package/package.json +1 -1
|
@@ -1,20 +1,15 @@
|
|
|
1
|
+
|
|
1
2
|
import fs from 'fs';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import {fileURLToPath} from 'url';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const projectRoot = path.join(__dirname, '..');
|
|
8
|
+
const srcRoot = path.join(projectRoot, 'src');
|
|
9
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
11
|
+
const excludeDirs = new Set(['node_modules', 'scripts', 'jest', 'src', '.git', '.github', '.idea']);
|
|
13
12
|
|
|
14
|
-
// Directories to exclude from scanning
|
|
15
|
-
const excludeDirs = ['node_modules', 'scripts', 'jest', 'src', '.git', '.github', '.idea'];
|
|
16
|
-
|
|
17
|
-
// Build exports object
|
|
18
13
|
const exports = {
|
|
19
14
|
'.': {
|
|
20
15
|
types: './index.d.ts',
|
|
@@ -24,55 +19,51 @@ const exports = {
|
|
|
24
19
|
}
|
|
25
20
|
};
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
function findIndexDirs(baseDir, relativePath = '')
|
|
29
|
-
{
|
|
30
|
-
const entries = fs.readdirSync(baseDir, {withFileTypes: true});
|
|
22
|
+
const importExportRegex = /((?:import|export)\s+(?:type\s+)?(?:[\s\S]*?from\s+)?['"])(\.{1,2}\/[^'"]+?)(['"])/g;
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
function scan(baseDir, relativePath = '')
|
|
25
|
+
{
|
|
26
|
+
for(const entry of fs.readdirSync(baseDir, {withFileTypes: true}))
|
|
33
27
|
{
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const fullPath = path.join(baseDir, entry.name);
|
|
28
|
+
const fullPath = path.join(baseDir, entry.name);
|
|
40
29
|
const newRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
41
|
-
const indexJsPath = path.join(fullPath, 'index.js');
|
|
42
30
|
|
|
43
|
-
|
|
44
|
-
if(fs.existsSync(indexJsPath))
|
|
31
|
+
if(entry.isDirectory())
|
|
45
32
|
{
|
|
46
|
-
|
|
47
|
-
types: `./${newRelativePath}/index.d.ts`,
|
|
48
|
-
import: `./${newRelativePath}/index.js`,
|
|
49
|
-
require: `./${newRelativePath}/index.js`,
|
|
50
|
-
default: `./${newRelativePath}/index.js`
|
|
51
|
-
};
|
|
33
|
+
if(excludeDirs.has(entry.name) || entry.name.startsWith('.')) continue;
|
|
52
34
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
if(fs.existsSync(path.join(fullPath, 'index.js')))
|
|
36
|
+
{
|
|
37
|
+
const jsPath = `./${newRelativePath}/index.js`;
|
|
38
|
+
const config = {types: `./${newRelativePath}/index.d.ts`, import: jsPath, require: jsPath, default: jsPath};
|
|
56
39
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
}
|
|
40
|
+
exports[`./${newRelativePath}`] = config;
|
|
41
|
+
exports[`./${newRelativePath}/index.js`] = config;
|
|
42
|
+
exports[`./${newRelativePath}/index.d.ts`] = {types: config.types, default: config.types};
|
|
43
|
+
}
|
|
63
44
|
|
|
64
|
-
|
|
65
|
-
|
|
45
|
+
scan(fullPath, newRelativePath);
|
|
46
|
+
}
|
|
47
|
+
else if(entry.isFile() && !entry.name.endsWith('.d.ts') && (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')))
|
|
48
|
+
{
|
|
49
|
+
const original = fs.readFileSync(fullPath, 'utf8');
|
|
50
|
+
const updated = original.replace(importExportRegex, (match, prefix, specifier, suffix) =>
|
|
51
|
+
path.extname(specifier) ? match : `${prefix}${specifier}.js${suffix}`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if(updated !== original)
|
|
55
|
+
{
|
|
56
|
+
fs.writeFileSync(fullPath, updated, 'utf8');
|
|
57
|
+
console.log(`Fixed extensions in: ${path.relative(projectRoot, fullPath)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
scan(projectRoot);
|
|
64
|
+
scan(srcRoot);
|
|
71
65
|
|
|
72
|
-
// Update package.json with new exports
|
|
73
66
|
packageJson.exports = exports;
|
|
74
|
-
|
|
75
|
-
// Write back to package.json
|
|
76
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, '\t') + '\n', 'utf8');
|
|
67
|
+
fs.writeFileSync(path.join(projectRoot, 'package.json'), JSON.stringify(packageJson, null, '\t') + '\n', 'utf8');
|
|
77
68
|
|
|
78
69
|
console.log(`Generated exports for ${Object.keys(exports).length} entries`);
|
package/.yarn/install-state.gz
CHANGED
|
Binary file
|