This repository has been archived by the owner on Jan 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
329 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
lib | ||
/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/lib/ | ||
/coverage/ | ||
docs/ | ||
/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import {fileURLToPath} from 'url' | ||
|
||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const dirname = path.dirname(__filename) | ||
|
||
|
||
function appendJsExtension(file) { | ||
const content = fs.readFileSync(file, 'utf8') | ||
const updatedContent = content.replace(/require\(['"]([^'"]+)['"]\)/g, (match, p1) => { | ||
// Append .js to relative paths if missing and not already ending with .js or .json | ||
if (p1.startsWith('.') && !p1.endsWith('.js') && !p1.endsWith('.json')) { | ||
return `require('${p1}.cjs')` | ||
} | ||
return match | ||
}) | ||
|
||
fs.writeFileSync(file, updatedContent, 'utf8') | ||
} | ||
|
||
function processDirectory(directory) { | ||
fs.readdirSync(directory, {withFileTypes: true}).forEach(dirent => { | ||
const fullPath = path.join(directory, dirent.name) | ||
if (dirent.isDirectory()) { | ||
processDirectory(fullPath) | ||
} | ||
else if (dirent.isFile() && dirent.name.endsWith('.cjs')) { | ||
appendJsExtension(fullPath) | ||
} | ||
}) | ||
} | ||
|
||
// The directory containing your compiled JavaScript files. | ||
// Adjust this path as necessary. | ||
const compiledDir = path.join(dirname, '../dist/cjs') | ||
processDirectory(compiledDir) | ||
|
||
console.log('Import paths have been fixed for CJS modules.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import {fileURLToPath} from 'url' | ||
|
||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const dirname = path.dirname(__filename) | ||
|
||
|
||
function addJsExtension(file) { | ||
const content = fs.readFileSync(file, 'utf8') | ||
const updatedContent = content.replace(/from\s+['"]([^'"]+)['"]/g, (match, p1) => { | ||
// Don't modify node_modules imports or absolute paths or URLs | ||
if (p1.startsWith('.') && !p1.endsWith('.js') && !p1.endsWith('.json')) { | ||
return `from '${p1}.mjs'` | ||
} | ||
return match | ||
}) | ||
|
||
fs.writeFileSync(file, updatedContent, 'utf8') | ||
} | ||
|
||
function processDirectory(directory) { | ||
fs.readdirSync(directory, {withFileTypes: true}).forEach(dirent => { | ||
const fullPath = path.join(directory, dirent.name) | ||
if (dirent.isDirectory()) { | ||
processDirectory(fullPath) | ||
} | ||
else if (dirent.isFile() && dirent.name.endsWith('.mjs')) { | ||
addJsExtension(fullPath) | ||
} | ||
}) | ||
} | ||
|
||
// The directory containing your compiled JavaScript files. | ||
// Adjust this path as necessary. | ||
const compiledDir = path.join(dirname, '../dist/esm') | ||
|
||
processDirectory(compiledDir) | ||
|
||
console.log('Import paths have been fixed.') |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"lib": [ | ||
"ES2022" | ||
], | ||
"strictNullChecks": true, | ||
"alwaysStrict": true, | ||
"moduleResolution": "node", | ||
"baseUrl": "./", | ||
"declaration": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"@sx/*": [ | ||
"./src/*" | ||
] | ||
}, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true, | ||
"strictPropertyInitialization": false | ||
}, | ||
"ts-node": { | ||
"esm": true | ||
}, | ||
"include": [ | ||
"./src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
], | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"import" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"outDir": "./dist/cjs" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"outDir": "./dist/esm" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.esm.json", | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"lib": [ | ||
"ES2022" | ||
], | ||
"strictNullChecks": true, | ||
"alwaysStrict": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"baseUrl": "./", | ||
"declaration": true, | ||
"outDir": "./lib", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"@sx/*": [ | ||
"./src/*" | ||
] | ||
}, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true, | ||
"strictPropertyInitialization": false | ||
"module": "ESNext", | ||
"outDir": "./dist/esm" | ||
}, | ||
"ts-node": { | ||
"esm": true | ||
}, | ||
"include": [ | ||
"./src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"lib" | ||
], | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"import" | ||
] | ||
"include": ["src/**/*"] | ||
} |
Oops, something went wrong.