From 44e115abd43712643573ef1fde4f38ea7dc232ce Mon Sep 17 00:00:00 2001 From: nmccready Date: Fri, 13 Sep 2024 09:51:45 -0400 Subject: [PATCH] feat: fix commonjs, removed rollup and umd --- package.json | 8 ++------ rollup.config.js | 28 ---------------------------- scripts/mockPublish | 10 ++++++++++ test/publish.test.js | 41 +++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 6 +++--- 5 files changed, 56 insertions(+), 37 deletions(-) delete mode 100644 rollup.config.js create mode 100755 scripts/mockPublish create mode 100644 test/publish.test.js diff --git a/package.json b/package.json index da73ae2..95b3afd 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "umd" ], "scripts": { - "build": "rollup -c ./rollup.config.js", + "build": "rm -rf lib && npx tsc", "coveralls": "cat ./coverage/lcov.info | coveralls", "docs:api:markdown": "npx typedoc --theme markdown --exclude ./src/test --out ./docs/api ./src", "docs:api:website": "npx typedoc --exclude ./src/test --out docs ./src", @@ -42,8 +42,6 @@ "@biiaidt/node-memwatch": "2.0.1", "@commitlint/cli": "^19", "@commitlint/config-conventional": "^19", - "@rollup/plugin-commonjs": "^26.0.1", - "@rollup/plugin-typescript": "^11.1.6", "@types/debug": "^4", "@types/jest": "^29.5.13", "@znemz/js-common-eslint-config": "^0.2.2", @@ -56,12 +54,10 @@ "hook-std": "0.X", "jest": "^29.7.0", "prettier": "^1.18.2", - "rollup": "4.21.3", "sort-package-json": "^2.10.1", "typescript": "^5.6.2" }, "engines": { "node": ">= 14" - }, - "umd": "umd/index.js" + } } diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index aa8b1c0..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,28 +0,0 @@ -const typescript = require('@rollup/plugin-typescript'); -const commonjs = require('@rollup/plugin-commonjs'); - -const pkg = require('./package.json'); - -module.exports = { - external: ['memoizee'], - input: 'src/index.ts', - output: [ - { - file: pkg.umd, - format: 'umd', - name: 'DebugFabulous', - globals: { - memoizee: 'memoizee', - }, - }, - { - file: pkg.main, - format: 'commonjs', - name: 'DebugFabulous', - globals: { - memoizee: 'memoizee', - }, - }, - ], - plugins: [commonjs(), typescript()], -}; diff --git a/scripts/mockPublish b/scripts/mockPublish new file mode 100755 index 0000000..1aa5223 --- /dev/null +++ b/scripts/mockPublish @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +set -o pipefail + +mkdir -p ./tmp +npm pack +mv *.tgz ./tmp +tar xvzf tmp/*.tgz -C ./tmp + +exit 0 diff --git a/test/publish.test.js b/test/publish.test.js new file mode 100644 index 0000000..bc8d493 --- /dev/null +++ b/test/publish.test.js @@ -0,0 +1,41 @@ +const os = require('os'); +const del = require('del'); + +const { exec } = require('child_process'); + +const isWindows = os.platform() === 'win32'; + +const cleanUp = async () => { + return del(['./tmp']); +}; + +function makeTestPackage(cb) { + if (isWindows) { + this.skip(); + } + + exec('./scripts/mockPublish', cb); +} + +describe('mock publish', () => { + beforeEach(makeTestPackage); + afterEach(cleanUp); + + // with regards to averting npm publishing disasters https://github.com/gulp-sourcemaps/gulp-sourcemaps/issues/246 + it('can load a published version', (done) => { + if (isWindows) { + this.skip(); + } + + try { + // attempt to load a packed / unpacked potential deployed version + // eslint-disable-next-line import/no-unresolved + require('../tmp/package/lib/index'); + } catch (error) { + done(error); + return; + } + + done(); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index bf4dfb6..8b322f6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,14 +5,14 @@ "noLib": false, "emitDecoratorMetadata": true, "noImplicitAny": false, - "module": "ESNext", + "module": "CommonJS", "target": "ES2020", "experimentalDecorators": true, "declaration": true, "noResolve": false, "moduleResolution": "node", - "outDir": ".tmp", + "outDir": "lib", "allowJs": true, }, - "exclude": ["node_modules", ".tmp", "jest.config.js"] + "include": ["src/**/*"] }