Skip to content

Commit

Permalink
Merge pull request #21 from shgysk8zer0/feature/cjs
Browse files Browse the repository at this point in the history
Add support for CJS and `require()`
  • Loading branch information
shgysk8zer0 authored Jun 7, 2023
2 parents 7f60c10 + 59442ad commit f07d468
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ dist
# Build artifacts
*.out.js
*.min.js
*.cjs
*.map.*
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test/
importmap.json
importmap.yaml
rollup.config.js
test.config.js
*.tgz
*.log
*.out.js
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v1.0.1] - 2023-06-06
## [v1.0.1] - 2023-06-07

### Added
- Add `@shgysk8zer0/npm-utils`
- Add `index.cjs` as module for use with `require()`

### Changed
- Use `@shgysk8zer0/npm-utils/importmap` instead of own resolver of specifiers
- Update Action for GitHub Release

### Fixed
- Update GitHub Release Action with correct permissions

### Changed
- Update Action for GitHub Release

## [v1.0.0] - 2023-05-13

### Added
Expand Down
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
"node": ">=18.0.0"
},
"private": false,
"main": "index.js",
"main": "index.cjs",
"module": "index.js",
"exports": {
".": {
"import": "index.js",
"require": "index.cjs"
}
},
"scripts": {
"test": "npm run lint:js && npm run build",
"test": "npm run lint:js && npm run test:plugin",
"preversion": "npm test",
"prepare": "npm run build:js",
"lint:js": "eslint .",
"fix:js": "eslint. --fix",
"build": "rollup -c",
"dev": "rollup -cw",
"build": "npm run build:js",
"build:js": "rollup -c rollup.config.js",
"test:plugin": "rollup -c test.config.js",
"create:lock": "npm i --package-lock-only",
"version:bump": "npm run version:bump:patch",
"version:bump:patch": "npm version --no-git-tag-version patch",
Expand Down
16 changes: 10 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { rollupImport } from './index.js';

export default {
input: 'test/index.js',
input: 'index.js',
external: [
'@shgysk8zer0/npm-utils/importmap', '@shgysk8zer0/npm-utils/fs',
'@shgysk8zer0/npm-utils/yaml', '@shgysk8zer0/npm-utils/json',
'@shgysk8zer0/npm-utils/utils', '@shgysk8zer0/npm-utils/exts',
'@shgysk8zer0/npm-utils/mimes', '@shgysk8zer0/npm-utils/conts',
'@shgysk8zer0/npm-utils/url', 'node:fs', 'js-yaml',
],
onwarn: warning => {
if (warning.code === 'MISSING_GLOBAL_NAME' || warning.code === 'UNRESOLVED_IMPORT') {
throw new Error(warning.message);
} else if (warning.code !== 'CIRCULAR_DEPENDENCY') {
console.warn(`(!) ${warning.message}`);
}
},
plugins: [rollupImport(['importmap.json'])],
output: {
file: 'test/index.out.js',
format: 'iife'
file: 'index.cjs',
format: 'cjs'
}
};
17 changes: 17 additions & 0 deletions test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { rollupImport } from './index.js';

export default {
input: 'test/index.js',
onwarn: warning => {
if (warning.code === 'MISSING_GLOBAL_NAME' || warning.code === 'UNRESOLVED_IMPORT') {
throw new Error(warning.message);
} else if (warning.code !== 'CIRCULAR_DEPENDENCY') {
console.warn(`(!) ${warning.message}`);
}
},
plugins: [rollupImport(['importmap.json'])],
output: {
file: 'test/index.out.js',
format: 'iife'
}
};

0 comments on commit f07d468

Please sign in to comment.