Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Use createRequire with createRequireFromPath as fallback #90

Merged
merged 4 commits into from
Mar 2, 2020

Conversation

ndresx
Copy link
Contributor

@ndresx ndresx commented Mar 2, 2020

createRequireFromPath is deprecated since Node v12.2.0 (source).

According to the contributing documentation, everything above Node v12 is fine, which means it would still need to support the previous implementation of createRequireFromPath.

Using createRequire was throwing a TS error, which why I have also updated the @types/node package. Therefore, the updated modules are now also part of this PR (separate commit via npm install), but I'm not sure how this process works here with committing them or not (same goes for the creation of the vendor file). Since it's a separate commit, it could be removed again, or the package update gets reverted (would have to type createRequire a bit differently then).

Fixes #83


PS: Could it be that there is a problem with the build pipeline step "Run actions/setup-node@v1"? https://github.com/facebookexperimental/rome/pull/90/checks?check_run_id=478564351

@ndresx ndresx force-pushed the fix-create-require-deprecation-warning branch from 609e928 to a2613d8 Compare March 2, 2020 01:34
@@ -240,7 +240,6 @@ export async function createClient(

req.on('upgrade', (res, socket, head) => {
if (res.headers['sec-websocket-accept'] !== digest) {
res.end();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end doesn't exist on this response type (https://nodejs.org/api/http.html#http_class_http_incomingmessage). socket.end() should be enough.

@sebmck
Copy link
Contributor

sebmck commented Mar 2, 2020

Thank you for doing this! I'll review when I get a chance.

PS: Could it be that there is a problem with the build pipeline step "Run actions/setup-node@v1"? https://github.com/facebookexperimental/rome/pull/90/checks?check_run_id=478564351

Yeah it appears so. It was reported here actions/setup-node#116 but it's happening consistently now.

@@ -208,7 +208,7 @@ export function createBridgeFromChildProcess<B extends Bridge>(
});

proc.on('message', msg => {
bridge.handleMessage(msg);
bridge.handleMessage(msg as BridgeMessage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the update of @types/node to its latest version, msg is now from type Serializable and not any anymore https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/child_process.d.ts#L60.

Argument of type 'Serializable' is not assignable to parameter of type 'BridgeMessage'.
Type 'string' is not assignable to type 'BridgeMessage'

Alternatively, I could change the argument type in handleMessage to make it more transparent, or revert the update of the types module if it's too much action overall for this.

packages/@romejs/node/index.ts Outdated Show resolved Hide resolved
Comment on lines 55 to 56
internalModule.createRequire(filename) ||
internalModule.createRequireFromPath(filename),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you meant was

Suggested change
internalModule.createRequire(filename) ||
internalModule.createRequireFromPath(filename),
internalModule.createRequire === undefined ? internalModule.createRequireFromPath(filename) : internalModule.createRequire(filename),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, yes indeed! 😓 I've changed it, thanks for finding this.

@sebmck sebmck merged commit 49ae78e into rome:master Mar 2, 2020
@sebmck
Copy link
Contributor

sebmck commented Mar 2, 2020

Looks good to me, thank you! Thanks for updating the definitions too!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Module.createRequire instead of Module.createRequireFromPath
3 participants