forked from react-hook-form/react-hook-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(esm): Use explicit .mjs extension for ESM
This ensures that Node always treats the ESM output as ESM, despite the package.json (implicit) type of commonjs. Bundlers that expect ESM, such as Next v12, no longer explode when encountering this module. Refs react-hook-form#7244 Refs react-hook-form#7095 Refs react-hook-form#7088 Refs react-hook-form/resolvers#271 Refs vercel/next.js#30750
- Loading branch information
Showing
5 changed files
with
66 additions
and
6 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,13 @@ | ||
[ | ||
"Controller", | ||
"FormProvider", | ||
"appendErrors", | ||
"get", | ||
"set", | ||
"useController", | ||
"useFieldArray", | ||
"useForm", | ||
"useFormContext", | ||
"useFormState", | ||
"useWatch" | ||
] |
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,22 @@ | ||
/** | ||
* This file, when executed in the postbuild lifecycle, ensures that | ||
* the CJS output is valid CJS according to the package.json spec. | ||
* | ||
* @see https://nodejs.org/docs/latest/api/packages.html#packages_determining_module_system | ||
*/ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const exported = require('react-hook-form'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
||
/** | ||
* When this fails, fine the update one-liner in ./assert-esm-exports.mjs | ||
*/ | ||
const expected = JSON.parse( | ||
fs.readFileSync( | ||
require('path').resolve(__dirname, './all-exports.json'), | ||
'utf-8', | ||
), | ||
); | ||
|
||
assert.deepStrictEqual(Object.keys(exported), expected); |
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,22 @@ | ||
/** | ||
* This file, when executed in the postbuild lifecycle, ensures that | ||
* the ESM output is valid ESM according to the package.json spec. | ||
* | ||
* @see https://nodejs.org/docs/latest/api/packages.html#packages_determining_module_system | ||
*/ | ||
import * as exported from 'react-hook-form'; | ||
import assert from 'assert'; | ||
import fs from 'fs'; | ||
|
||
/** | ||
* A shell one-liner to update this array when neccessary (run from root of repo): | ||
* node -e "import('react-hook-form').then((mod) => console.log(JSON.stringify(Object.keys(mod), null, 2)))" > scripts/rollup/all-exports.json | ||
*/ | ||
const expected = JSON.parse( | ||
fs.readFileSync( | ||
new URL('./all-exports.json', import.meta.url).pathname, | ||
'utf-8', | ||
), | ||
); | ||
|
||
assert.deepStrictEqual(Object.keys(exported), expected); |
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