Skip to content

Commit

Permalink
feat(typescript): using tsup
Browse files Browse the repository at this point in the history
  • Loading branch information
srod committed Dec 8, 2022
1 parent 7ad720e commit ed35ea1
Show file tree
Hide file tree
Showing 77 changed files with 639 additions and 895 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@node-minify/run": "workspace:*",
"@node-minify/sqwish": "workspace:*",
"@node-minify/terser": "workspace:*",
"@node-minify/types": "workspace:*",
"@node-minify/uglify-es": "workspace:*",
"@node-minify/uglify-js": "workspace:*",
"@node-minify/utils": "workspace:*",
Expand All @@ -65,6 +66,7 @@
"node-notifier": "10.0.1",
"prettier": "2.8.0",
"rimraf": "3.0.2",
"tsup": "6.5.0",
"typescript": "4.9.3",
"vitest": "0.25.3"
},
Expand Down
24 changes: 9 additions & 15 deletions packages/babel-minify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@
"lib": "dist",
"test": "__tests__"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/esm/types/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
},
"types": "./dist/cjs/types/index.d.ts",
"main": "./dist/cjs/index.js",
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"files": [
"dist/**/*"
],
Expand All @@ -47,8 +41,8 @@
},
"scripts": {
"clean": "pnpm dlx rimraf dist",
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
"prepack": "npm run build"
"build": "npm run clean && tsup src/index.ts --format cjs,esm --dts --clean",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@node-minify/utils": "workspace:*",
Expand Down
9 changes: 0 additions & 9 deletions packages/babel-minify/tsconfig-cjs.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/babel-minify/tsconfig.json

This file was deleted.

27 changes: 14 additions & 13 deletions packages/clean-css/__tests__/clean-css.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* MIT Licensed
*/

import { afterAll, beforeAll, describe, expect, test } from 'vitest';
import { describe, expect, test } from 'vitest';
import minify from '../../core/src';
import cleanCss from '../src';
import { filesCSS } from '../../../tests/files-path';
import { runOneTest, tests } from '../../../tests/fixtures';
import { Options } from '../../../tests/types';

const compressorLabel = 'clean-css';
const compressor = cleanCss;
Expand All @@ -20,21 +21,21 @@ describe('Package: clean-css', () => {
tests.commoncss.forEach(options => {
runOneTest({ options, compressorLabel, compressor, sync: true });
});
test('should compress with some options', () =>
new Promise(done => {
const options = {};
options.minify = {
compressor,
input: filesCSS.fileCSS,
output: filesCSS.fileCSSOut,
options: {
sourceMap: {
filename: filesCSS.fileCSSSourceMaps,
url: filesCSS.fileCSSSourceMaps
test('should compress with some options', (): Promise<void> =>
new Promise<void>(done => {
const options: Options = {
minify: {
compressor,
input: filesCSS.fileCSS,
output: filesCSS.fileCSSOut,
options: {
sourceMap: {
filename: filesCSS.fileCSSSourceMaps,
url: filesCSS.fileCSSSourceMaps
}
}
}
};

options.minify.callback = (err, min) => {
expect(err).toBeNull();
expect(min).not.toBeNull();
Expand Down
24 changes: 9 additions & 15 deletions packages/clean-css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@
"lib": "dist",
"test": "__tests__"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/esm/types/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
},
"types": "./dist/cjs/types/index.d.ts",
"main": "./dist/cjs/index.js",
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"files": [
"dist/**/*"
],
Expand All @@ -47,8 +41,8 @@
},
"scripts": {
"clean": "pnpm dlx rimraf dist",
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
"prepack": "npm run build"
"build": "npm run clean && tsup src/index.ts --format cjs,esm --dts --clean",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@node-minify/utils": "workspace:*",
Expand Down
9 changes: 0 additions & 9 deletions packages/clean-css/tsconfig-cjs.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/clean-css/tsconfig.json

This file was deleted.

5 changes: 3 additions & 2 deletions packages/cli/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest';
import childProcess from 'child_process';
import { Settings } from '@node-minify/types';
import * as cli from '../src';
import { filesJS } from '../../../tests/files-path';
import { TESTS_TIMEOUT } from '../../../constants';
import { TESTS_TIMEOUT } from '../../../tests/constants';

describe(
'Package: cli',
Expand Down Expand Up @@ -39,7 +40,7 @@ describe(
});
test('should minify to throw with yui error', () => {
const spy = vi.spyOn(cli, 'run');
const options = {
const options: Settings = {
compressor: 'yui',
input: filesJS.oneFile,
output: filesJS.fileJSOut
Expand Down
22 changes: 8 additions & 14 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@
"lib": "dist",
"test": "__tests__"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/esm/types/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"types": "./dist/cjs/types/index.d.ts",
"main": "./dist/cjs/index.js",
"files": [
"bin",
"dist/**/*"
Expand All @@ -50,8 +44,8 @@
},
"scripts": {
"clean": "pnpm dlx rimraf dist",
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
"prepack": "npm run build"
"build": "npm run clean && tsup src/index.ts --format cjs,esm --dts --clean",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@node-minify/core": "workspace:*",
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import chalk from 'chalk';
import { compress } from './compress';
import { spinnerStart, spinnerStop, spinnerError } from './spinner';
import { Cli, Settings, Result } from '@node-minify/types';
import { Settings, Result } from '@node-minify/types';

// export interface Options {
// compressorLabel: string | Function;
Expand Down Expand Up @@ -46,15 +46,15 @@ let silence = false;
/**
* Run one compressor.
*/
const runOne = (cli: Cli): Promise<Result> => {
const runOne = (cli: Settings): Promise<Result> => {
return new Promise<Result>((resolve, reject) => {
const compressor =
typeof cli.compressor === 'string' ? require(`@node-minify/${cli.compressor}`).default : cli.compressor;

const options: Settings = {
compressorLabel: cli.compressor,
compressor,
input: cli.input.split(','),
input: typeof cli.input === 'string' ? cli.input.split(',') : '',
output: cli.output
};

Expand Down Expand Up @@ -85,7 +85,7 @@ const runOne = (cli: Cli): Promise<Result> => {
/**
* Run cli.
*/
const run = (cli: Cli) => {
const run = (cli: Settings) => {
silence = !!cli.silence;

if (!silence) {
Expand Down
9 changes: 0 additions & 9 deletions packages/cli/tsconfig-cjs.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/cli/tsconfig.json

This file was deleted.

Loading

0 comments on commit ed35ea1

Please sign in to comment.