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

Update TypeScript to the latest stable version #124

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"build:clean": "rimraf dist && yarn build",
"build": "tsc --project .",
"build": "tsc --project tsconfig.build.json",
"changelog": "node dist/cli.js"
},
"dependencies": {
Expand Down Expand Up @@ -61,7 +61,7 @@
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.6",
"typescript": "^4.2.4"
"typescript": "~4.8.4"
},
"lavamoat": {
"allowScripts": {
Expand Down
55 changes: 37 additions & 18 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ async function validate({
}
}

/**
* Returns whether an error has an error code or not.
*
* @param error - The error to check.
* @returns True if the error is a real error and has a code property, false otherwise.
*/
function hasErrorCode(error: unknown): error is Error & { code: unknown } {
return (
error instanceof Error &&
Object.prototype.hasOwnProperty.call(error, 'code')
);
}

type InitOptions = {
changelogPath: string;
repoUrl: string;
Expand Down Expand Up @@ -303,14 +316,16 @@ async function main() {
);
}
} catch (error) {
if (error.code === 'ENOENT') {
return exitWithError(
`Root directory specified does not exist: '${projectRootDirectory}'`,
);
} else if (error.code === 'EACCES') {
return exitWithError(
`Access to root directory is forbidden by file access permissions: '${projectRootDirectory}'`,
);
if (hasErrorCode(error)) {
if (error.code === 'ENOENT') {
return exitWithError(
`Root directory specified does not exist: '${projectRootDirectory}'`,
);
} else if (error.code === 'EACCES') {
return exitWithError(
`Access to root directory is forbidden by file access permissions: '${projectRootDirectory}'`,
);
}
}
throw error;
}
Expand All @@ -328,15 +343,19 @@ async function main() {
const manifest = JSON.parse(manifestText);
currentVersion = manifest.version;
} catch (error) {
if (error.code === 'ENOENT') {
return exitWithError(
`Package manifest not found at path: '${manifestPath}'\nRun this script from the project root directory, or set the project directory using the '--root' flag.`,
);
} else if (error.code === 'EACCES') {
return exitWithError(
`Access to package manifest is forbidden by file access permissions: '${manifestPath}'`,
);
} else if (error.name === 'SyntaxError') {
if (hasErrorCode(error)) {
if (error.code === 'ENOENT') {
return exitWithError(
`Package manifest not found at path: '${manifestPath}'\nRun this script from the project root directory, or set the project directory using the '--root' flag.`,
);
} else if (error.code === 'EACCES') {
return exitWithError(
`Access to package manifest is forbidden by file access permissions: '${manifestPath}'`,
);
}
}

if (error instanceof Error && error.name === 'SyntaxError') {
return exitWithError(
`Package manifest cannot be parsed as JSON: '${manifestPath}'`,
);
Expand Down Expand Up @@ -376,7 +395,7 @@ async function main() {
// eslint-disable-next-line no-bitwise
await fs.access(changelogPath, fsConstants.F_OK | fsConstants.W_OK);
} catch (error) {
if (error.code === 'ENOENT') {
if (hasErrorCode(error) && error.code === 'ENOENT') {
return exitWithError(`File does not exist: '${changelogPath}'`);
}
return exitWithError(`File is not writable: '${changelogPath}'`);
Expand Down
13 changes: 13 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"inlineSources": true,
"noEmit": false,
"outDir": "dist",
"rootDir": "src",
"sourceMap": true
},
"include": ["./src/**/*.ts"],
"exclude": ["./src/**/*.test.ts"]
}
16 changes: 6 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"inlineSources": true,
"forceConsistentCasingInFileNames": true,
"lib": ["ES2020"],
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"moduleResolution": "node",
"noEmit": true,
"noErrorTruncation": true,
"strict": true,
"target": "ES2019",
"typeRoots": ["./node_modules/@types"]
"target": "ES2019"
},
"exclude": ["**/*.test.ts"],
"include": ["./src/**/*.ts"]
"exclude": ["./dist/**/*"]
}
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ __metadata:
rimraf: ^3.0.2
semver: ^7.3.5
ts-jest: ^26.5.6
typescript: ^4.2.4
typescript: ~4.8.4
yargs: ^17.0.1
bin:
auto-changelog: dist/cli.js
Expand Down Expand Up @@ -7181,23 +7181,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^4.2.4":
version: 4.2.4
resolution: "typescript@npm:4.2.4"
"typescript@npm:~4.8.4":
version: 4.8.4
resolution: "typescript@npm:4.8.4"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 89c397df192f239359ad798b96d8e8d552e12c0c189ac5676cec4c20c410d6eec636b8e59a88f2aef0a56d961a9678d99c400099be9b7cae2f7b062eb4b7b171
checksum: 3e4f061658e0c8f36c820802fa809e0fd812b85687a9a2f5430bc3d0368e37d1c9605c3ce9b39df9a05af2ece67b1d844f9f6ea8ff42819f13bcb80f85629af0
languageName: node
linkType: hard

"typescript@patch:typescript@^4.2.4#~builtin<compat/typescript>":
version: 4.2.4
resolution: "typescript@patch:typescript@npm%3A4.2.4#~builtin<compat/typescript>::version=4.2.4&hash=701156"
"typescript@patch:typescript@~4.8.4#~builtin<compat/typescript>":
version: 4.8.4
resolution: "typescript@patch:typescript@npm%3A4.8.4#~builtin<compat/typescript>::version=4.8.4&hash=701156"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: eb86e0e8022e5297f7a7b871b6edfbf33b57049416ada8bf97c358760125c7c79f074fbebd1b8e8230f858ae05eb22ad0e805e8f6acd5eae1fa886681624c15e
checksum: 301459fc3eb3b1a38fe91bf96d98eb55da88a9cb17b4ef80b4d105d620f4d547ba776cc27b44cc2ef58b66eda23fe0a74142feb5e79a6fb99f54fc018a696afa
languageName: node
linkType: hard

Expand Down