Skip to content

Commit

Permalink
feat: convert to hybrid ES/CommonJS npm package (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n committed Jun 21, 2024
1 parent 2d30078 commit ebe4769
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
- run: npm run test
- run: npm run test:types
- run: npm run coverage
- run: npm run test:web
- run: npm run build
env:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.idea
/.tmp
/.nyc_output
/node_modules
/npm-debug.log
/coverage
Expand Down
9 changes: 0 additions & 9 deletions .mocharc.js

This file was deleted.

6 changes: 6 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recursive": true,
"spec": "test/**/*.js",
"reporter": "mocha-multi-reporters",
"reporter-options": "configFile=test/mocha-multi.json"
}
2 changes: 0 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.idea
/.tmp
/.nyc_output
/.github
/coverage
/node_modules
Expand All @@ -16,7 +15,6 @@
/.mocharc.js
/.npmignore
/.npmrc
/.nycrc
/.releaserc
/tmp-test-bundle.js.LICENSE.txt
/.codeclimate.yml
Expand Down
8 changes: 0 additions & 8 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@
"files": ".prettierrc",
"options": { "parser": "json" }
},
{
"files": ".babelrc",
"options": { "parser": "json" }
},
{
"files": ".eslintrc",
"options": { "parser": "json" }
},
{
"files": ".nycrc",
"options": { "parser": "json" }
}
]
}
File renamed without changes.
38 changes: 16 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"redundant",
"duplication"
],
"type": "module",
"version": "1.1.5",
"homepage": "https://github.com/swaggerexpert/json-api-merge",
"license": "BSD-3-Clause",
Expand All @@ -24,20 +25,25 @@
"url": "https://swaggerexpert.com/"
},
"sideEffects": false,
"main": "./lib/index.js",
"module": "./es/index.js",
"jsnext:main": "./es/index.js",
"main": "./lib/index.cjs",
"unpkg": "dist/web.standalone.min.js",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.mjs",
"require": "./lib/index.cjs"
},
"./package.json": "./package.json"
},
"scripts": {
"lint": "better-npm-run lint",
"lint:fix": "better-npm-run lint:fix",
"test": "better-npm-run test",
"test": "mocha",
"test:web": "better-npm-run test:web",
"test:types": "dtslint ./types",
"test:bundle-create": "better-npm-run test:bundle-create",
"test:bundle-clean": "better-npm-run test:bundle-clean",
"coverage": "better-npm-run coverage",
"build": "better-npm-run build",
"build:es": "better-npm-run build:es",
"build:commonjs": "better-npm-run build:commonjs",
Expand All @@ -48,42 +54,30 @@
"betterScripts": {
"lint": "eslint ./ && tslint --project types/tsconfig.json -c types/tslint.json types/**/*.ts",
"lint:fix": "eslint ./ --fix && tslint --fix --project types/tsconfig.json -c types/tslint.json types/**/*.ts",
"test": {
"command": "mocha",
"env": {
"BABEL_ENV": "commonjs"
}
},
"test:web": "testem ci",
"test:bundle-create": "webpack --config webpack.config-test.web.js --progress",
"test:bundle-create": "webpack --config webpack.config-test.web.cjs --progress",
"test:bundle-clean": "rimraf tmp-test-bundle.js",
"coverage": {
"command": "nyc mocha",
"env": {
"BABEL_ENV": "coverage"
}
},
"build": "npm run build:es && npm run build:commonjs && npm run build:umd",
"build:es": {
"command": "babel src --out-dir es",
"command": "babel src/index.js --out-file es/index.mjs",
"env": {
"BABEL_ENV": "es"
}
},
"build:commonjs": {
"command": "babel src --out-dir lib",
"command": "babel src/index.js --out-file lib/index.cjs",
"env": {
"BABEL_ENV": "commonjs"
}
},
"build:umd": {
"command": "webpack --config webpack.config.js --progress",
"command": "webpack --config webpack.config.cjs --progress",
"env": {
"BABEL_ENV": "browser"
}
},
"prepublishOnly": "npm run clean && npm run lint && npm run test && npm run test:web && npm run build",
"clean": "rimraf .nyc_output .tmp coverage tmp-test-bundle.js dist lib es json-api-merge-0.1.0.tgz test-results.xml"
"clean": "rimraf .tmp tmp-test-bundle.js dist lib es test-results.xml"
},
"readme": "README.md",
"dependencies": {
Expand Down
9 changes: 8 additions & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
"mocha/no-top-level-hooks": 2,
"mocha/no-identical-title": 2,
"mocha/no-nested-tests": 2,
"mocha/no-exclusive-tests": 2
"mocha/no-exclusive-tests": 2,
"import/extensions": [
"error",
"always",
{
"ignorePackages": true,
}
]
},
"overrides": [{
"files": ["mocha-bootstrap.js"],
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from 'chai';

import jsonApiMerge from '../src';
import jsonApiMerge from '../src/index.js';

describe('jsonApiMerge', function () {
context('given single resource', function () {
Expand Down
6 changes: 0 additions & 6 deletions test/mocha-bootstrap.js

This file was deleted.

24 changes: 24 additions & 0 deletions webpack.config-test.web.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const path = require('node:path');
const { globSync } = require('glob'); // eslint-disable-line import/no-extraneous-dependencies

module.exports = {
mode: 'production',
target: 'web',
entry: [
...globSync(path.join(__dirname, './test/*.js'), {}),
],
output: {
path: path.resolve('.'),
filename: 'tmp-test-bundle.js',
},
module: {
rules: [
{
test: /\.(js)$/,
loader: 'babel-loader',
},
],
},
};
45 changes: 0 additions & 45 deletions webpack.config-test.web.js

This file was deleted.

File renamed without changes.

0 comments on commit ebe4769

Please sign in to comment.