From 9381d6eddc8ead7820f0a0140232898748195fdc Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Fri, 1 Dec 2023 05:05:21 +0200 Subject: [PATCH] Add cjs build --- .gitignore | 1 + index.mjs | 1 - package.json | 23 +++++++++++++++++++---- rollup.config.mjs | 9 +++++++++ test/cjs.js | 15 +++++++++++++++ test.mjs => test/test.mjs | 2 +- 6 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 rollup.config.mjs create mode 100644 test/cjs.js rename test.mjs => test/test.mjs (94%) diff --git a/.gitignore b/.gitignore index 4c444c6..b97d4dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ coverage/ +build/ *.log diff --git a/index.mjs b/index.mjs index 9a1fe24..f2843b6 100644 --- a/index.mjs +++ b/index.mjs @@ -4,5 +4,4 @@ import Cf from './categories/Cf/regex.mjs'; import P from './categories/P/regex.mjs'; import Z from './categories/Z/regex.mjs'; -export default { Any, Cc, Cf, P, Z }; export { Any, Cc, Cf, P, Z }; diff --git a/package.json b/package.json index 88820a7..a83a615 100644 --- a/package.json +++ b/package.json @@ -4,19 +4,34 @@ "description": "Micro subset of unicode data files for markdown-it projects.", "repository": "markdown-it/uc.micro", "license": "MIT", - "exports": "./index.mjs", + "main": "build/index.cjs.js", + "module": "index.mjs", + "exports": { + ".": { + "require": "./build/index.cjs.js", + "import": "./index.mjs" + }, + "./*": { + "require": "./*", + "import": "./*" + } + }, "files": [ + "index.mjs", "categories/", "properties/", - "index.mjs" + "build/" ], "scripts": { - "test": "mocha", - "update": "node update.mjs && npm test" + "test": "npm run build && mocha", + "build": "rollup -c", + "update": "node update.mjs && npm test", + "prepublishOnly": "npm run build" }, "devDependencies": { "@unicode/unicode-15.1.0": "^1.5.2", "mocha": "^10.2.0", + "rollup": "^4.6.1", "shelljs": "^0.8.5" } } diff --git a/rollup.config.mjs b/rollup.config.mjs new file mode 100644 index 0000000..47b2a79 --- /dev/null +++ b/rollup.config.mjs @@ -0,0 +1,9 @@ +export default [ + { + input: 'index.mjs', + output: { + file: 'build/index.cjs.js', + format: 'cjs' + } + } +] diff --git a/test/cjs.js b/test/cjs.js new file mode 100644 index 0000000..775e62a --- /dev/null +++ b/test/cjs.js @@ -0,0 +1,15 @@ +'use strict' +/* eslint-env mocha */ + +const ucm = require('../') +const assert = require('assert') + +describe('CJS', () => { + it('require', () => { + assert.ok(ucm.Any) + assert.ok(ucm.Cc) + assert.ok(ucm.Cf) + assert.ok(ucm.P) + assert.ok(ucm.Z) + }) +}) diff --git a/test.mjs b/test/test.mjs similarity index 94% rename from test.mjs rename to test/test.mjs index efe79cf..55b8b37 100644 --- a/test.mjs +++ b/test/test.mjs @@ -1,5 +1,5 @@ import assert from 'node:assert' -import ucm from './index.mjs' +import * as ucm from '../index.mjs' describe('Unicode classes', () => { it('Any', () => {