Skip to content

Commit

Permalink
Merge pull request #408 from antonioru/fix/package-specifiers
Browse files Browse the repository at this point in the history
fix(specifiers): Updates package.json specifiers
  • Loading branch information
antonioru committed Mar 18, 2023
2 parents 08917a0 + 98a2187 commit e00bcb4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -45,7 +45,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare distribution
run: cp package.json README.md LICENSE.txt CHANGELOG.md CONTRIBUTING.md CODE_OF_CONDUCT.md ./dist
run: |
node scripts/generate-exports.js
cp package.json README.md LICENSE.txt CHANGELOG.md CONTRIBUTING.md CODE_OF_CONDUCT.md ./dist
- name: Publish
run: |
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Expand Up @@ -1029,4 +1029,10 @@ Errored release

### Fixes

- Deprecated github actions version
- Deprecated GitHub actions version

## [4.2.1] - 2023-03-18

### Fixes

- package.json specifiers (exports)
4 changes: 0 additions & 4 deletions package.json
Expand Up @@ -102,10 +102,6 @@
"webpack": "5.76.1"
},
"exports": {
".": {
"import": "./esm/index.js",
"require": "./index.js"
},
"./useWindowScroll": {
"import": "./esm/useWindowScroll.js",
"require": "./useWindowScroll.js"
Expand Down
11 changes: 2 additions & 9 deletions scripts/generate-exports.js
Expand Up @@ -11,26 +11,19 @@ const srcFiles = globSync(`${srcPath}/*.ts`)
.map((file) => file.replace(`${srcPath}/`, '').replace('.ts', ''))
.filter((file) => file !== 'index')

const defaultExports = {
'.': {
import: './esm/index.js',
require: './index.js'
}
}

const exportsObj = srcFiles.reduce((acc, file) => ({
...acc,
[`./${file}`]: {
import: `./esm/${file}.js`,
require: `./${file}.js`
}
}), defaultExports)
}), {})

const packageJsonText = fs.readFileSync(pkgPath)
const packageJson = JSON.parse(packageJsonText)

const nextPackageJson = { ...packageJson, exports: exportsObj }

console.log('\nUPDATING EXPORTS: ', nextPackageJson)
console.log('\nUPDATING EXPORTS: ', Object.keys(exportsObj))

fs.writeFileSync(pkgPath, JSON.stringify(nextPackageJson, null, 2))

0 comments on commit e00bcb4

Please sign in to comment.