Skip to content

Commit

Permalink
feat: convert project to TypeScript (#52), require node v16
Browse files Browse the repository at this point in the history
* fix: eslint-prettier error

When attempting to fix eslint rules in file, the following error appeared

```Error: "prettier/vue" has been merged into "prettier" in eslint-config-prettier 8.0.0. See: https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21```

Reading the linked changelog, it seemed the fix was to simply only use the prettier/recommended extension. Simplified eslintrc to reflect this.

* deps: install typescript

* misc: ignore builds

* feat: convert to typescript

* fix: eslint-prettier error

When attempting to fix eslint rules in file, the following error appeared

```Error: "prettier/vue" has been merged into "prettier" in eslint-config-prettier 8.0.0. See: https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21```

Reading the linked changelog, it seemed the fix was to simply only use the prettier/recommended extension. Simplified eslintrc to reflect this.

* fix: eslint errors in typescript-files

Eslint was complaining about various keywords being reserved and was unerlining them. Fixed by installing `typescript-eslint` according to [this guide](https://typescript-eslint.io/getting-started)

* misc: apply eslint rules

reformat and clean-up using new eslint config

* chore(deps): bump mkdirp

Bumped because >=2 includes typings and seemingly no other breaking changes

* chore: fix eslint end-of-line error

On my Windows machine eslint was constantly complaining about line endings. Fixed using this answer https://stackoverflow.com/a/53769213

* feat: ambient typings for js module

Add ambient typings for another-npm-registry-client

* refactor: move file

Move types file into types folder

* refactor: add basic type for NpmClient

Based on usage. Could use some cleanup

* refactor: declare global types

Declare types instead of exporting them for easier use

* refactor: improve ambient type declarations

Improve type declarations for another-npm-registry-client by reading it's docs

* conf: bump target es version

Bump to ES2020 to match Node 14 after consulting https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping

* deps: downgrade node types

Downgrade to match node version

* refactor: add correct response type

* feat: typecheck errors

Add some custom type assertions for expected errors

* misc: add shared idea files

* refactor: clean up imports

* refactor: make variables constant

Make variables constant where possible

* misc: remove outdated ts-ignores

* refactor: handle potential null

* fix: add better type for upm auth

Previously mistakenly used the same auth type as for npm

* refactor: fix type warning

Instead of assigning different auth properties separately, assign all at once in the different if branches in order to avoid type warnings

* fix: type parameter

* misc: delete outdates jsdoc comment

* fix: unhandled null values

Check token and _auth for null before respective usage

* fix: type error

Convert results array to string before logging to avoid type error. I joined the results using line-breaks, don't know if this is intended.

* refactor: use existing type

Previously added a custom type for npm search options even though such a type already exists

* fix: add missing import

Response type was ambiguous without import

* fix: remove extraneous declare

It seems to cause problems and to be honest I don't know if we need it

* fix: type error

The result of the nmp-search function is search.Result but because we know the openupm server actually returns PkgInfo objects we can change the type

* fix: remove extraneous ts-ignore

* fix: type error

Instead of initializing env with empty object, populate with default members in order to avoid type error

* fix: type error

Type was declared incorrectly

* misc: remove extraneous ts-ignores

* fix: type error

Based on line 166 we can assume that undefined is actually a valid value for the version. Adjusted signature accordingly

* refactor: prevent value conversion

Explicitly check for undefined instead using auto-conversion to avoid "isGitOrLocal" becoming equal to some string

* misc: handle undefined

Probably unrecoverable, so we just throw

* refactor: shorten and fix type error

Use Object.assign instead of copying all properties manually. This also avoids an error for unchecked property access

* fix: type error

Make properties of options optional

* fix: potential undefined error

* fix: extraneous parameter

According to the signature of search it expects only one parameter. Removed the second empty string parameter

* fix: editing readonly list

The array given to findIndex seems to be readonly so instead we modify the original lines array

* fix: type errors

First we type-assert the result of npmFetch.json to match its usage. We can assume that it is either an array or record of packages.
We also move the log until later in the code and log the objects variable instead of results, since that is guarantied to be an array. We also convert the array to a string using join for better logging

* refactor: simplify property access

* fix: handle undefined

Throw if no latest version could be found

* fix: handle undefined

Throw if upm-config dir-path could not be resolved

* fix: handle null

Throw if editor-version could not be parsed

* fix: type errors

Add type for editor-version regex matches in order to prevent type errors. Also on line 501 I removed the toLowerCase() because it does not seem to be necessary looking at the regex

* fix: getLatestVersion should return undefined

By reading the tests I saw that this function should return undefined if the version could not be determined. Changed signature

* refactor: remove outdated logic

See #52 (comment)

* fix: handle undefined

Throw if version of package to add could not be determined

* fix: fix type error

Allow undefined as possible value for version in table-row

* refactor: assert undefined

Version is required in order to print package info

* refactor: remove unused imports

* fix: unhandled undefined

Latest version is required

* fix: handle undefined

Require latest version

* refactor: simplify ifs

Remove unnecessary boolean comparisons

* refactor: inline return

* fix: incorrectly registering errors

The callbacks used by the registry client incorrectly always registered an error. Added a null-check to only create an error when something actually went wrong

* misc: add build npm script

Just runs tsc

* misc: reformat file

* fix: undefined error

Some tests where failing because there was a throw if a package with unknown version was added. Undefined was an acceptable value, so the throw was removed and the types changed accordingly

* conf: generate sourcemaps

To enable debugging

* Revert "refactor: simplify ifs"

This reverts commit f9ae663.

* fix: incorrect type for env properties

* fix: invalid type assertion

* refactor: change type

Expand type for package names with attached version to allow all strings for the version. The reason is that the string after the @ may not only include versions such as "1.0.0" but also tags such as "beta"

* refactor: rename type

Rename PkgVersion to PkgVersionInfo in order to be more in line with PkgInfo type name

* refactor: rename type

Extend type name to be clearer

* refactor: simplify package name type

A package-name can now include a version or not

* refactor: make property optional

As indicated by usage

* refactor: extract utility function

Extract function that checks if the version-name of a package is a url version, such as a git-url. For now we do this as before by just checking if it starts with one of the common protocols

* refactor: rename type

Shorten version-name type name to just version, since it no longer conflicts with version-info

* refactor: remove extraneous if

IDE tells me that this if is always false

* refactor: rename module

To match type

* refactor: extract and rename function

Rename the parseName function to splitPackageName to better reflect it's purpose. Also moved to separate module

* misc: convert tests to typescript

Whole bunch of TS errors still, but the tests all pass

* refactor: optimize test imports

* refactor: convert type declarations to exports

Seems to cause less TS problems that way

* refactor: make properties optional

According to usage in tests, these properties should be optional

* fix: type errors in test utils

Add return and param types for all functions

* misc: reformat files

* refactor: make properties optional

According to usage in tests

* fix: inspector type errors in tests

Type inspect variables. We force the null because it is guaranteed that inspectors will be set before a test is run

* refactor: remove unused constants

* refactor: remove unnecessary await

a

* refactor: make properties optional

According to usage in tests

* refactor: fix null and undefined warnings in test

Assert not-null or not-undefined where applicable

* misc: drop outdated test

* feat: fix type error

Allow partial pkg-infos in order to satisfy test setups

* fix: null error

Allow null as seen in tests

* conf: simplify test script

ts-mocha already compiles TS

* misc: change bin structure

Instead of building the package using tsc and then running the js file, we can run using ts-node. That way we only need ts files in the project. For this to work a few changes needed to be done:
- Removed the initial empty index file
- Moved bin-files into lib
- Converted bin files to ts and renamed them to index/index-cn
- Changed the shebang in the index files to use ts-node. This also requires ts-node is a dependency of the package
- Adjust tsconfig in order to work with ts-node

Seems like the package still works as intended. It might take a little bit longer to run because of the additional compile step

* misc: add missing typescript dependency

Seems like mocha requires it

* chore: fix eslint-prettier error (#50)

When attempting to fix eslint rules in file, the following error appeared

```Error: "prettier/vue" has been merged into "prettier" in eslint-config-prettier 8.0.0. See: https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21```

Reading the linked changelog, it seemed the fix was to simply only use the prettier/recommended extension. Simplified eslintrc to reflect this.

* deps: install typescript

* misc: ignore builds

* feat: convert to typescript

* fix: eslint errors in typescript-files

Eslint was complaining about various keywords being reserved and was unerlining them. Fixed by installing `typescript-eslint` according to [this guide](https://typescript-eslint.io/getting-started)

* misc: apply eslint rules

reformat and clean-up using new eslint config

* chore(deps): bump mkdirp

Bumped because >=2 includes typings and seemingly no other breaking changes

* chore: fix eslint end-of-line error

On my Windows machine eslint was constantly complaining about line endings. Fixed using this answer https://stackoverflow.com/a/53769213

* feat: ambient typings for js module

Add ambient typings for another-npm-registry-client

* refactor: move file

Move types file into types folder

* refactor: add basic type for NpmClient

Based on usage. Could use some cleanup

* refactor: declare global types

Declare types instead of exporting them for easier use

* refactor: improve ambient type declarations

Improve type declarations for another-npm-registry-client by reading it's docs

* conf: bump target es version

Bump to ES2020 to match Node 14 after consulting https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping

* deps: downgrade node types

Downgrade to match node version

* refactor: add correct response type

* feat: typecheck errors

Add some custom type assertions for expected errors

* misc: add shared idea files

* refactor: clean up imports

* refactor: make variables constant

Make variables constant where possible

* misc: remove outdated ts-ignores

* refactor: handle potential null

* fix: add better type for upm auth

Previously mistakenly used the same auth type as for npm

* refactor: fix type warning

Instead of assigning different auth properties separately, assign all at once in the different if branches in order to avoid type warnings

* fix: type parameter

* misc: delete outdates jsdoc comment

* fix: unhandled null values

Check token and _auth for null before respective usage

* fix: type error

Convert results array to string before logging to avoid type error. I joined the results using line-breaks, don't know if this is intended.

* refactor: use existing type

Previously added a custom type for npm search options even though such a type already exists

* fix: add missing import

Response type was ambiguous without import

* fix: remove extraneous declare

It seems to cause problems and to be honest I don't know if we need it

* fix: type error

The result of the nmp-search function is search.Result but because we know the openupm server actually returns PkgInfo objects we can change the type

* fix: remove extraneous ts-ignore

* fix: type error

Instead of initializing env with empty object, populate with default members in order to avoid type error

* fix: type error

Type was declared incorrectly

* misc: remove extraneous ts-ignores

* fix: type error

Based on line 166 we can assume that undefined is actually a valid value for the version. Adjusted signature accordingly

* refactor: prevent value conversion

Explicitly check for undefined instead using auto-conversion to avoid "isGitOrLocal" becoming equal to some string

* misc: handle undefined

Probably unrecoverable, so we just throw

* refactor: shorten and fix type error

Use Object.assign instead of copying all properties manually. This also avoids an error for unchecked property access

* fix: type error

Make properties of options optional

* fix: potential undefined error

* fix: extraneous parameter

According to the signature of search it expects only one parameter. Removed the second empty string parameter

* fix: editing readonly list

The array given to findIndex seems to be readonly so instead we modify the original lines array

* fix: type errors

First we type-assert the result of npmFetch.json to match its usage. We can assume that it is either an array or record of packages.
We also move the log until later in the code and log the objects variable instead of results, since that is guarantied to be an array. We also convert the array to a string using join for better logging

* refactor: simplify property access

* fix: handle undefined

Throw if no latest version could be found

* fix: handle undefined

Throw if upm-config dir-path could not be resolved

* fix: handle null

Throw if editor-version could not be parsed

* fix: type errors

Add type for editor-version regex matches in order to prevent type errors. Also on line 501 I removed the toLowerCase() because it does not seem to be necessary looking at the regex

* fix: getLatestVersion should return undefined

By reading the tests I saw that this function should return undefined if the version could not be determined. Changed signature

* refactor: remove outdated logic

See #52 (comment)

* fix: handle undefined

Throw if version of package to add could not be determined

* fix: fix type error

Allow undefined as possible value for version in table-row

* refactor: assert undefined

Version is required in order to print package info

* refactor: remove unused imports

* fix: unhandled undefined

Latest version is required

* fix: handle undefined

Require latest version

* refactor: simplify ifs

Remove unnecessary boolean comparisons

* refactor: inline return

* fix: incorrectly registering errors

The callbacks used by the registry client incorrectly always registered an error. Added a null-check to only create an error when something actually went wrong

* misc: add build npm script

Just runs tsc

* misc: reformat file

* fix: undefined error

Some tests where failing because there was a throw if a package with unknown version was added. Undefined was an acceptable value, so the throw was removed and the types changed accordingly

* conf: generate sourcemaps

To enable debugging

* Revert "refactor: simplify ifs"

This reverts commit f9ae663.

* fix: incorrect type for env properties

* fix: invalid type assertion

* refactor: change type

Expand type for package names with attached version to allow all strings for the version. The reason is that the string after the @ may not only include versions such as "1.0.0" but also tags such as "beta"

* refactor: rename type

Rename PkgVersion to PkgVersionInfo in order to be more in line with PkgInfo type name

* refactor: rename type

Extend type name to be clearer

* refactor: simplify package name type

A package-name can now include a version or not

* refactor: make property optional

As indicated by usage

* refactor: extract utility function

Extract function that checks if the version-name of a package is a url version, such as a git-url. For now we do this as before by just checking if it starts with one of the common protocols

* refactor: rename type

Shorten version-name type name to just version, since it no longer conflicts with version-info

* refactor: remove extraneous if

IDE tells me that this if is always false

* refactor: rename module

To match type

* refactor: extract and rename function

Rename the parseName function to splitPackageName to better reflect it's purpose. Also moved to separate module

* misc: convert tests to typescript

Whole bunch of TS errors still, but the tests all pass

* refactor: optimize test imports

* refactor: convert type declarations to exports

Seems to cause less TS problems that way

* refactor: make properties optional

According to usage in tests, these properties should be optional

* fix: type errors in test utils

Add return and param types for all functions

* misc: reformat files

* refactor: make properties optional

According to usage in tests

* fix: inspector type errors in tests

Type inspect variables. We force the null because it is guaranteed that inspectors will be set before a test is run

* refactor: remove unused constants

* refactor: remove unnecessary await

a

* refactor: make properties optional

According to usage in tests

* refactor: fix null and undefined warnings in test

Assert not-null or not-undefined where applicable

* misc: drop outdated test

* feat: fix type error

Allow partial pkg-infos in order to satisfy test setups

* fix: null error

Allow null as seen in tests

* conf: simplify test script

ts-mocha already compiles TS

* misc: change bin structure

Instead of building the package using tsc and then running the js file, we can run using ts-node. That way we only need ts files in the project. For this to work a few changes needed to be done:
- Removed the initial empty index file
- Moved bin-files into lib
- Converted bin files to ts and renamed them to index/index-cn
- Changed the shebang in the index files to use ts-node. This also requires ts-node is a dependency of the package
- Adjust tsconfig in order to work with ts-node

Seems like the package still works as intended. It might take a little bit longer to run because of the additional compile step

* misc: add missing typescript dependency

Seems like mocha requires it

* Bump node version

Bump from 14 to 16. See #52 (comment)

* misc: better build structure

See #52 (comment)

* misc: add CI TS build step

* misc: remove unused dependencies

* misc: regenerate package lock

* chore: update .node-version to 16

* chore: update .npmignore

* fix: add the npm clean script to run before build

---------

Co-authored-by: Favo Yang <favoyang@gmail.com>
  • Loading branch information
ComradeVanti and favoyang authored Nov 1, 2023
1 parent 14f8ba5 commit 8e68b9a
Show file tree
Hide file tree
Showing 53 changed files with 8,019 additions and 14,038 deletions.
19 changes: 14 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
module.exports = {
root: true,
env: {
node: true
node: true,
},
extends: [
"eslint:recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
],
rules: {
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
}
}
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
"prettier/prettier": [
"error",
{
endOfLine: "auto",
},
],
},
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
};
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* text=auto
bin/openupm text eol=lf
bin/openupm-cn text eol=lf
lib/index.ts text eol=lf
lib/index.ts-cn text eol=lf
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
node-version: [16.x]
name: CI - node ${{ matrix.node-version }}
steps:
- uses: actions/checkout@v3
Expand All @@ -19,13 +19,15 @@ jobs:
run: npm ci
- name: npm run test
run: npm run test

release:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
- name: Build
run: npm run build
- name: Release
uses: cycjimmy/semantic-release-action@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ typings/
# next.js build output
.next
.vscode/settings.json

# builds

/lib
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/openupm-cli.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
16
12 changes: 11 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@
.gitattributes
.eslintrc.js
test/
.vscode/
.vscode/
src/
!lib/
.github/
.idea/
.nvmrc
.node-version
.releaserc.json
tsconfig.json
*.tgz
*.tar.gz
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14
v16
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The command-line tool installs the 3rd-party registry as a scoped registry and m
## Installation

- Requires [nodejs 14.18 or above](https://nodejs.org/en/download/).
- Requires [nodejs 16 or above](https://nodejs.org/en/download/).
- Install via npm:

```
Expand Down Expand Up @@ -74,7 +74,7 @@ internal/modules/cjs/loader.js:818
Error: Cannot find module 'node:net'
```

Please install [nodejs 14.18 or above](https://nodejs.org/en/download/).
Please install [nodejs 16 or above](https://nodejs.org/en/download/).

## China region

Expand Down
4 changes: 2 additions & 2 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ openupm-cli基于Unity对带作用域的软件仓库(scoped registry)的支
## 安装

- 请先自行安装[nodejs 14.18或以上版本](https://nodejs.org/en/download/).
- 请先自行安装[nodejs 16或以上版本](https://nodejs.org/en/download/).
- 通过npm安装:

```
Expand Down Expand Up @@ -74,7 +74,7 @@ internal/modules/cjs/loader.js:818
Error: Cannot find module 'node:net'
```

请安装[nodejs 14.18或以上版本](https://nodejs.org/en/download/)
请安装[nodejs 16或以上版本](https://nodejs.org/en/download/)


## 中国区
Expand Down
3 changes: 0 additions & 3 deletions bin/openupm

This file was deleted.

Empty file removed index.js
Empty file.
23 changes: 0 additions & 23 deletions lib/client.js

This file was deleted.

35 changes: 0 additions & 35 deletions lib/cmd-deps.js

This file was deleted.

99 changes: 0 additions & 99 deletions lib/cmd-search.js

This file was deleted.

13 changes: 0 additions & 13 deletions lib/error-handler.js

This file was deleted.

Loading

0 comments on commit 8e68b9a

Please sign in to comment.