Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed an error using import syntax when the moduleResolution field is nodeNext in tsconfig.json #1521

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions bin/publish.mjs
@@ -0,0 +1,26 @@
import fs from "fs"
import path from "path"
import { fileURLToPath } from "url"

const publishHookType = process.argv[2]

const __dirname = fileURLToPath(import.meta.url)
const packageJsonPath = path.resolve(__dirname, "../../package.json")
const backupPath = path.resolve(__dirname, "../.backup-package.json")

const readFile = (path) => fs.readFileSync(path, "utf-8")
const writeFile = (path, content) => fs.writeFileSync(path, content, "utf-8")

if (publishHookType === "pre" && !fs.existsSync(backupPath)) {
const packageJson = readFile(packageJsonPath)
const packageObj = JSON.parse(packageJson)
writeFile(backupPath, packageJson)
delete packageObj.type

const newPackageJson = JSON.stringify(packageObj, null, 2)
writeFile(packageJsonPath, newPackageJson)
} else if (publishHookType === "post") {
const packageJson = readFile(backupPath)
writeFile(packageJsonPath, packageJson)
fs.unlinkSync(backupPath)
}
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -70,6 +70,8 @@
"ls-lint": "ls-lint",
"build": "rollup --config --silent",
"prepare": "npm run build",
"prepublishOnly": "node bin/publish.mjs pre",
"postpublish": "node bin/publish.mjs post",
"postversion": "echo 'Remember to update the changelog!'"
},
"keywords": [
Expand Down