-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: ie11 build * use fs-extra instead of move-file Ref: #143
- Loading branch information
Showing
6 changed files
with
98 additions
and
5 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,54 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { move } = require('fs-extra'); | ||
const microbundle = require('microbundle'); | ||
const getResolversName = require('./get-resolvers-name'); | ||
|
||
const IE11_PATH = 'ie11'; | ||
const OUTPUT = 'dist'; | ||
|
||
(async () => { | ||
console.log(`Build IE11 resolvers to ${OUTPUT}`); | ||
const resolvers = getResolversName(); | ||
|
||
for await (let resolver of resolvers) { | ||
console.log(`> Build ${resolver}`); | ||
const filePath = path.join(resolver, 'package.json'); | ||
|
||
const resolverPkg = JSON.parse(fs.readFileSync(filePath)); | ||
const resolverPkgCopy = Object.assign({}, resolverPkg); | ||
|
||
// Temporary update `types` field | ||
resolverPkg.types = `${IE11_PATH}/index.d.ts`; | ||
|
||
await fs.writeFileSync(filePath, JSON.stringify(resolverPkg, null, 2)); | ||
|
||
try { | ||
await microbundle({ | ||
cwd: resolver, | ||
output: IE11_PATH, | ||
globals: '@hookform/resolvers=hookformResolvers', | ||
format: 'cjs', | ||
alias: 'react-hook-form=react-hook-form/dist/index.ie11', | ||
}); | ||
|
||
// Move `./{resolver}/ie11` -> `./dist/ie11/{resolver}` | ||
await move( | ||
`${resolver}/${IE11_PATH}`, | ||
`${OUTPUT}/${IE11_PATH}/${resolver}`, | ||
{ | ||
overwrite: true, | ||
}, | ||
); | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} finally { | ||
// Revert back changes on `{resolver}/package.json` | ||
await fs.writeFileSync( | ||
filePath, | ||
JSON.stringify(resolverPkgCopy, null, 2), | ||
); | ||
} | ||
} | ||
})(); |
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,18 @@ | ||
const fs = require('fs'); | ||
const getResolversName = require('./get-resolvers-name'); | ||
|
||
(async () => { | ||
console.log('Checking IE11 bundles...'); | ||
const resolvers = getResolversName(); | ||
|
||
for await (const resolver of resolvers) { | ||
console.log(`> Checking ${resolver} IE11 bundle`); | ||
const file = fs.readFileSync(`dist/ie11/${resolver}/${resolver}.js`); | ||
|
||
if (!file.includes('react-hook-form/dist/index.ie11')) { | ||
throw new Error( | ||
'IE11 bundle should require `react-hook-form/dist/index.ie11`', | ||
); | ||
} | ||
} | ||
})(); |
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,7 @@ | ||
const pkg = require('../package.json'); | ||
|
||
module.exports = function () { | ||
return Object.keys(pkg.exports) | ||
.map((e) => e.replace(/(\.\/|\.)/, '').replace(/package.*/, '')) | ||
.filter(Boolean); | ||
}; |
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