Skip to content

Commit

Permalink
feat(typescript): init rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
srod committed Dec 8, 2022
1 parent ebe5da8 commit 7ad720e
Show file tree
Hide file tree
Showing 124 changed files with 3,529 additions and 4,334 deletions.
4 changes: 1 addition & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"env": {
"node": true,
"es6": true,
"jasmine": true,
"jest": true
"es6": true
},
"plugins": ["prettier"],
"extends": ["eslint:recommended", "prettier"],
Expand Down
14 changes: 0 additions & 14 deletions .github/dependabot.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: pnpm install --no-frozen-lockfile

- name: Run tests
run: pnpm run setup && pnpm test
run: pnpm build && pnpm coverage
env:
CI: true

Expand Down
16 changes: 0 additions & 16 deletions babel.config.js

This file was deleted.

1 change: 1 addition & 0 deletions constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TESTS_TIMEOUT = 30000;
54 changes: 19 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": {
"name": "Rodolphe Stoclin",
"email": "rodolphe@2clics.net",
"url": "http://2clics.net"
"url": "https://www.2clics.net"
},
"license": "MIT",
"private": true,
Expand All @@ -18,27 +18,24 @@
},
"packageManager": "pnpm@7.18.0",
"scripts": {
"setup": "npm run clean:packages && npm run build",
"build": "npm run clean:build && npm run build-js",
"build-js": "pnpm lerna exec --parallel -- babel --root-mode upward src --out-dir lib --copy-files",
"build": "lerna run build",
"clean": "pnpm clean:build; pnpm clean:packages",
"clean:build": "pnpm dlx rimraf packages/*/dist",
"clean:packages": "pnpm lerna clean -y",
"clean:test": "pnpm dlx rimraf tests/tmp/*.{js,js.map,css,html}",
"coverage": "vitest run --coverage",
"eslint": "eslint --ignore-path .gitignore packages",
"lerna": "lerna",
"lint": "npm run eslint || true",
"pretest": "npm run build && npm run eslint",
"test": "jest",
"posttest": "npm run clean:coverage",
"clean:build": "pnpm dlx rimraf packages/*/lib",
"clean:coverage": "pnpm dlx rimraf tests/tmp/*.{js,js.map,css,html}",
"clean:packages": "pnpm lerna clean -y",
"showpack": "pnpm lerna pack --dry",
"lint": "pnpm eslint || true",
"postcoverage": "pnpm clean:test",
"pretest": "pnpm build; pnpm eslint",
"publish-latest": "NPM_CONFIG_OTP=xxx pnpm lerna publish --tag-version-prefix ''",
"publish-next": "NPM_CONFIG_OTP=xxx pnpm lerna publish --tag-version-prefix '' --preid beta --npm-tag next",
"prettier-project": "prettier --write './packages/**/{bin,src,__tests__}/**/*.js'"
"prettier-project": "prettier --write './packages/**/{bin,src,__tests__}/**/*.js'",
"showpack": "pnpm lerna pack --dry",
"test": "vitest"
},
"devDependencies": {
"@babel/cli": "7.19.3",
"@babel/core": "7.20.5",
"@babel/preset-env": "7.20.2",
"@node-minify/babel-minify": "workspace:*",
"@node-minify/clean-css": "workspace:*",
"@node-minify/cli": "workspace:*",
Expand All @@ -57,22 +54,22 @@
"@node-minify/uglify-js": "workspace:*",
"@node-minify/utils": "workspace:*",
"@node-minify/yui": "workspace:*",
"babel-core": "6.26.3",
"babel-jest": "29.3.1",
"babel-preset-env": "1.7.0",
"@types/node": "18.11.10",
"@vitest/coverage-c8": "0.25.3",
"eslint": "8.29.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"husky": "8.0.2",
"jest": "27.5.1",
"lerna": "6.1.0",
"lint-staged": "13.1.0",
"node-notifier": "10.0.1",
"prettier": "2.8.0",
"rimraf": "3.0.2"
"rimraf": "3.0.2",
"typescript": "4.9.3",
"vitest": "0.25.3"
},
"lint-staged": {
"*.js": [
"*.ts": [
"prettier --write",
"git add"
]
Expand All @@ -87,18 +84,5 @@
"hooks": {
"pre-commit": "lint-staged"
}
},
"jest": {
"collectCoverage": true,
"coverageDirectory": "<rootDir>/coverage/",
"notify": true,
"projects": [
"<rootDir>/packages/*"
],
"rootDir": "./",
"testPathIgnorePatterns": [
"/node_modules/",
".history"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* MIT Licensed
*/

import babelMinify from '../src/babel-minify';
import { describe } from 'vitest';
import babelMinify from '../src';
import { runOneTest, tests } from '../../../tests/fixtures';

const compressorLabel = 'babel-minify';
Expand Down
31 changes: 27 additions & 4 deletions packages/babel-minify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@
"author": "Rodolphe Stoclin <srodolphe@gmail.com>",
"homepage": "https://github.com/srod/node-minify/tree/master/packages/babel-minify#readme",
"license": "MIT",
"main": "lib/babel-minify.js",
"engines": {
"node": ">=14.0.0"
},
"directories": {
"lib": "lib",
"lib": "dist",
"test": "__tests__"
},
"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",
"files": [
"lib"
"dist/**/*"
],
"publishConfig": {
"access": "public"
Expand All @@ -32,9 +45,19 @@
"bugs": {
"url": "https://github.com/srod/node-minify/issues"
},
"scripts": {
"clean": "pnpm dlx rimraf dist",
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
"prepack": "npm run build"
},
"dependencies": {
"@node-minify/utils": "^7.0.0",
"@node-minify/utils": "workspace:*",
"babel-core": "6.26.3",
"babel-preset-minify": "0.5.2"
},
"devDependencies": {
"@node-minify/types": "workspace:*",
"@types/babel-core": "^6.25.7",
"babel-preset-env": "1.7.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@
import { transform } from 'babel-core';
import minify from 'babel-preset-minify';
import { utils } from '@node-minify/utils';
import { MinifierOptions } from '@node-minify/types';

// interface Options {
// sourceMap?: boolean;
// _sourceMap?: { url: string } | boolean;
// babelrc?: {};
// presets?: [];
// }

// interface Settings {
// options: Options;
// content: string;
// output: string;
// }

// interface MinifierOptions {
// settings: Settings;
// content: string;
// callback: Function;
// index: number;
// }

interface BabelOptions {
presets: string[];
}

/**
* Run babel-minify.
Expand All @@ -18,16 +43,16 @@ import { utils } from '@node-minify/utils';
* @param {String} content
* @param {Function} callback
*/
const minifyBabel = ({ settings, content, callback, index }) => {
let babelOptions = {
const minifyBabel = ({ settings, content, callback, index }: MinifierOptions) => {
let babelOptions: BabelOptions = {
presets: []
};

if (settings.options.babelrc) {
if (settings && settings.options && settings.options.babelrc) {
babelOptions = JSON.parse(utils.readFile(settings.options.babelrc));
}

if (settings.options.presets) {
if (settings && settings.options && settings.options.presets) {
const babelrcPresets = babelOptions.presets || [];
babelOptions.presets = babelrcPresets.concat(settings.options.presets);
}
Expand All @@ -36,8 +61,8 @@ const minifyBabel = ({ settings, content, callback, index }) => {
babelOptions.presets = babelOptions.presets.concat([minify]);
}

const contentMinified = transform(content, babelOptions);
if (!settings.content) {
const contentMinified = transform(content || '', babelOptions);
if (settings && !settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified.code, index });
}
if (callback) {
Expand All @@ -49,4 +74,4 @@ const minifyBabel = ({ settings, content, callback, index }) => {
/**
* Expose `minifyBabel()`.
*/
module.exports = minifyBabel;
export default minifyBabel;
9 changes: 9 additions & 0 deletions packages/babel-minify/tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"target": "es2015"
},
"include": ["./src"]
}
9 changes: 9 additions & 0 deletions packages/babel-minify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm",
"target": "esnext"
},
"include": ["./src"]
}
45 changes: 0 additions & 45 deletions packages/clean-css/__tests__/clean-css.test.js

This file was deleted.

47 changes: 47 additions & 0 deletions packages/clean-css/__tests__/clean-css.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
* node-minify
* Copyright(c) 2011-2022 Rodolphe Stoclin
* MIT Licensed
*/

import { afterAll, beforeAll, 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';

const compressorLabel = 'clean-css';
const compressor = cleanCss;

describe('Package: clean-css', () => {
tests.commoncss.forEach(options => {
runOneTest({ options, compressorLabel, compressor });
});
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
}
}
};

options.minify.callback = (err, min) => {
expect(err).toBeNull();
expect(min).not.toBeNull();

done();
};

minify(options.minify);
}));
});
Loading

0 comments on commit 7ad720e

Please sign in to comment.