Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#873@trivial: Continue on implementation.
- Loading branch information
1 parent
5d28f9e
commit bd2ac68
Showing
18 changed files
with
849 additions
and
74 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 +1 @@ | ||
module.exports = require('../happy-dom/.prettierrc.js'); | ||
module.exports = require('../happy-dom/.prettierrc.cjs'); |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import GlobalRegistrator from './GlobalRegistrator'; | ||
import GlobalRegistrator from './GlobalRegistrator.js'; | ||
|
||
export { GlobalRegistrator }; |
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
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,100 @@ | ||
/* eslint-disable no-console*/ | ||
/* eslint-disable @typescript-eslint/no-var-requires*/ | ||
|
||
const Path = require('path'); | ||
const FS = require('fs'); | ||
|
||
process.on('unhandledRejection', (reason) => { | ||
console.error(reason); | ||
process.exit(1); | ||
}); | ||
|
||
main(); | ||
|
||
function getArguments() { | ||
const args = { | ||
dir: null, | ||
fromExt: null, | ||
toExt: null | ||
}; | ||
|
||
for (const arg of process.argv) { | ||
if (arg.startsWith('--dir=')) { | ||
args.dir = arg.split('=')[1]; | ||
} else if (arg.startsWith('--fromExt=')) { | ||
args.fromExt = arg.split('=')[1]; | ||
} else if (arg.startsWith('--toExt=')) { | ||
args.toExt = arg.split('=')[1]; | ||
} | ||
} | ||
|
||
return args; | ||
} | ||
|
||
async function readDirectory(directory) { | ||
const resolvedDirectory = Path.resolve(directory); | ||
const files = await FS.promises.readdir(resolvedDirectory); | ||
const statsPromises = []; | ||
let allFiles = []; | ||
|
||
for (const file of files) { | ||
const filePath = Path.join(resolvedDirectory, file); | ||
statsPromises.push( | ||
FS.promises.stat(filePath).then((stats) => { | ||
if (stats.isDirectory()) { | ||
return readDirectory(filePath).then((files) => (allFiles = allFiles.concat(files))); | ||
} | ||
allFiles.push(filePath); | ||
}) | ||
); | ||
} | ||
|
||
await Promise.all(statsPromises); | ||
|
||
return allFiles; | ||
} | ||
|
||
async function renameFiles(files, args) { | ||
const newFiles = files.map((file) => ({ | ||
oldPath: file, | ||
newPath: file.replace(args.fromExt, args.toExt) | ||
})); | ||
const writePromises = []; | ||
|
||
for (const file of newFiles) { | ||
writePromises.push( | ||
FS.promises.readFile(file.oldPath).then((content) => { | ||
return FS.promises | ||
.writeFile( | ||
file.newPath, | ||
content | ||
.toString() | ||
.replace( | ||
new RegExp(`${args.fromExt.replace('.', '\\.')}\\.map`, 'g'), | ||
`${args.toExt}.map` | ||
) | ||
.replace( | ||
new RegExp(`${args.fromExt.replace('.', '\\.')}(["'])`, 'g'), | ||
`${args.toExt}$1` | ||
) | ||
) | ||
.then(() => { | ||
if (file.oldPath !== file.newPath) { | ||
return FS.promises.unlink(file.oldPath); | ||
} | ||
}); | ||
}) | ||
); | ||
} | ||
|
||
await Promise.all(writePromises); | ||
} | ||
|
||
async function main() { | ||
const args = getArguments(); | ||
if (!args.dir || !args.fromExt || !args.toExt) { | ||
throw new Error('Invalid arguments'); | ||
} | ||
const files = await readDirectory(args.dir); | ||
await renameFiles(files, args); | ||
} |
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
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 +1 @@ | ||
module.exports = require('../happy-dom/.prettierrc.js'); | ||
module.exports = require('../happy-dom/.prettierrc.cjs'); |
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,34 +1,6 @@ | ||
import ChildProcess from 'node:child_process'; | ||
import FS from 'node:fs'; | ||
import Path from 'node:path'; | ||
|
||
// ES6 tests | ||
await Promise.all([ | ||
import('./tests/Fetch.test.js'), | ||
import('./tests/XMLHttpRequest.test.js'), | ||
import('./tests/WindowGlobals.test.js') | ||
import('./tests/WindowGlobals.test.js'), | ||
import('./tests/CommonJS.test.cjs') | ||
]); | ||
|
||
// CommonJS test | ||
const packageJSONPath = Path.resolve('./package.json'); | ||
const packageJSONContent = FS.readFileSync(packageJSONPath); | ||
|
||
FS.writeFileSync(packageJSONPath, packageJSONContent.replace('"type": "module",', '')); | ||
|
||
ChildProcess.exec('node ./tests/CommonJS.test.js', {}, (error, stdout, stderr) => { | ||
FS.writeFileSync(packageJSONPath, packageJSONContent); | ||
|
||
if (stdout) { | ||
console.log(stdout); | ||
} | ||
if (stderr) { | ||
console.error(stderr); | ||
} | ||
if (error) { | ||
console.error(stderr); | ||
} | ||
|
||
if (error || stderr) { | ||
process.exit(1); | ||
} | ||
}); |
2 changes: 1 addition & 1 deletion
2
...egration-test/test/tests/CommonJS.test.js → ...gration-test/test/tests/CommonJS.test.cjs
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
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
Oops, something went wrong.