-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #319 BREAKING CHANGE: Requires node >18
- Loading branch information
Showing
14 changed files
with
3,138 additions
and
1,959 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
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,5 @@ | ||
module.exports = { | ||
rules: { | ||
'import/no-extraneous-dependencies': 'off', | ||
}, | ||
} |
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
File renamed without changes.
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
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
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,57 @@ | ||
/** | ||
It converts | ||
```ts | ||
exports.default = vuePlugin; | ||
exports.parseVueRequest = parseVueRequest; | ||
``` | ||
to | ||
```ts | ||
module.exports = vuePlugin; | ||
module.exports.default = vuePlugin; | ||
module.exports.parseVueRequest = parseVueRequest; | ||
``` | ||
*/ | ||
|
||
import { readFileSync, writeFileSync } from 'node:fs' | ||
import colors from 'picocolors' | ||
|
||
const indexPath = 'dist/index.cjs' | ||
let code = readFileSync(indexPath, 'utf-8') | ||
|
||
const matchMixed = code.match(/\nexports.default = (\w+);/) | ||
if (matchMixed) { | ||
const name = matchMixed[1] | ||
|
||
const lines = code.trimEnd().split('\n') | ||
|
||
// search from the end to prepend `modules.` to `export[xxx]` | ||
for (let i = lines.length - 1; i > 0; i--) { | ||
if (lines[i].startsWith('exports')) lines[i] = 'module.' + lines[i] | ||
else { | ||
// at the beginning of exports, export the default function | ||
lines[i] += `\nmodule.exports = ${name};` | ||
break | ||
} | ||
} | ||
|
||
writeFileSync(indexPath, lines.join('\n')) | ||
|
||
console.log(colors.bold(`${indexPath} CJS patched`)) | ||
process.exit(0) | ||
} | ||
|
||
const matchDefault = code.match(/\nmodule.exports = (\w+);/) | ||
|
||
if (matchDefault) { | ||
code += `module.exports.default = ${matchDefault[1]};\n` | ||
writeFileSync(indexPath, code) | ||
console.log(colors.bold(`${indexPath} CJS patched`)) | ||
process.exit(0) | ||
} | ||
|
||
console.error(colors.red(`${indexPath} CJS patch failed`)) | ||
process.exit(1) |
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.