Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES module #21

Merged
merged 16 commits into from
Mar 11, 2024
3 changes: 3 additions & 0 deletions karma.conf.js → karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const browsers = (process.env.TEST_BROWSERS || 'ChromeHeadless').split(',');

// use puppeteer provided Chrome for testing
process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function(karma) {
karma.set({

Expand Down
2,585 changes: 1,676 additions & 909 deletions package-lock.json

Large diffs are not rendered by default.

44 changes: 24 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
"name": "min-dom",
"version": "4.1.0",
"description": "A minimal dom utility toolbelt",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
nikku marked this conversation as resolved.
Show resolved Hide resolved
},
"./package.json": "./package.json"
},
"scripts": {
"all": "run-s lint test test:types distro",
"all": "run-s lint test check-types test:distro",
"pretest": "run-s bundle",
"bundle": "rollup -c",
"distro": "run-s bundle test:integration",
"lint": "eslint .",
"prepare": "run-s distro",
"test": "karma start",
"test:types": "tsc --project test/integration --pretty --noEmit",
"test:integration": "karma start test/integration/karma.conf.js"
"lint": "eslint . --ext js,cjs",
"prepare": "run-s bundle",
"test": "karma start karma.conf.cjs",
"check-types": "tsc --noEmit",
"test:distro": "karma start test/integration/karma.conf.cjs"
},
"keywords": [
"dom",
Expand Down Expand Up @@ -41,24 +46,23 @@
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-node-resolve": "^14.1.0",
"@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1",
"chai": "^4.3.6",
"@types/chai": "^4.3.12",
"@types/mocha": "^10.0.6",
"chai": "^4.4.1",
"eslint": "^8.23.1",
"eslint-plugin-bpmn-io": "^0.15.1",
"karma": "^6.4.0",
"karma": "^6.4.3",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-firefox-launcher": "^2.1.2",
"karma-chrome-launcher": "^3.2.0",
"karma-firefox-launcher": "^2.1.3",
"karma-mocha": "^2.0.1",
"karma-webpack": "^5.0.0",
"mocha": "^10.0.0",
"mocha": "^10.3.0",
"npm-run-all": "^4.1.2",
"puppeteer": "^17.1.3",
"puppeteer": "^22.4.0",
"rollup": "^2.79.0",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.8.3",
"webpack": "^5.74.0"
"webpack": "^5.90.3"
},
"files": [
"dist"
Expand Down
30 changes: 3 additions & 27 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { terser } from 'rollup-plugin-terser';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

import pkg from './package.json';

const pkgExport = pkg.exports['.'];

function pgl(plugins = []) {
return [
nodeResolve({
Expand All @@ -15,36 +16,11 @@ function pgl(plugins = []) {
];
}

const umdDist = 'dist/min-dom.js';

export default [

// browser-friendly UMD build
{
input: 'lib/index.js',
output: {
name: 'MinDom',
file: umdDist,
format: 'umd'
},
plugins: pgl()
},
{
input: 'lib/index.js',
output: {
name: 'MinDom',
file: umdDist.replace(/\.js$/, '.min.js'),
format: 'umd'
},
plugins: pgl([
terser()
])
},
{
input: 'lib/index.js',
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
{ file: pkgExport.import, format: 'es', sourcemap: true }
],
plugins: pgl()
}
Expand Down
2 changes: 1 addition & 1 deletion test/attr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
attr,
domify
} from '../lib';
} from 'min-dom';


describe('attr', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/bind.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
event
} from '../lib';
} from 'min-dom';


describe('event', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/classes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
classes,
domify
} from '../lib';
} from 'min-dom';


describe('classes', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/clear.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
clear,
domify
} from '../lib';
} from 'min-dom';


describe('clear', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/closest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
closest,
domify,
query
} from '../lib';
} from 'min-dom';


describe('closest', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/delegate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
delegate
} from '../lib';
} from 'min-dom';


describe('delegate', function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// use puppeteer provided Chrome for testing
process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function(karma) {
karma.set({

Expand All @@ -9,10 +12,8 @@ module.exports = function(karma) {
],

files: [
'dist/min-dom.min.js',
'test/integration/umd.js',
{ pattern: 'test/integration/module.js', type: 'module' },
{ pattern: 'dist/index.esm.js', included: false }
{ pattern: 'dist/index.js', included: false }
],

reporters: [ 'progress' ],
Expand Down
2 changes: 1 addition & 1 deletion test/integration/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
queryAll,
remove,
event
} from '../../dist/index.esm.js';
} from '../../dist/index.js';


describe('module export', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/ts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as MinDom from '../..';
import * as MinDom from 'min-dom';

import { expect } from 'chai';

Expand Down
13 changes: 0 additions & 13 deletions test/integration/tsconfig.json

This file was deleted.

45 changes: 0 additions & 45 deletions test/integration/umd.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/matches.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
domify,
matches
} from '../lib';
} from 'min-dom';


describe('matches', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
domify,
query,
queryAll
} from '../lib';
} from 'min-dom';


describe('query', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/remove.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
domify,
remove
} from '../lib';
} from 'min-dom';


describe('remove', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/style.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
domify,
assignStyle
} from '../lib';
} from 'min-dom';


describe('style', function() {
Expand Down
12 changes: 12 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"strict": true,
"target": "ES2018",
"module": "Node16",
"moduleResolution": "NodeNext"
},
"include": [
"lib",
"test"
]
}