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

feat(typescript): rewrite #1598

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 coverage
env:
CI: true

Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tag-version-prefix=""
strict-peer-dependencies = false
auto-install-peers = true
lockfile = true
enable-pre-post-scripts = true
16 changes: 0 additions & 16 deletions babel.config.js

This file was deleted.

3 changes: 2 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "nextra-docs-template",
"version": "0.0.1",
"version": "8.0.1-beta.0",
"description": "Nextra docs template",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
},
"npmClient": "pnpm",
"useWorkspaces": true,
"version": "7.0.0"
"version": "8.0.2-beta.0"
}
60 changes: 24 additions & 36 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,25 @@
},
"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",
"eslint": "eslint --ignore-path .gitignore packages",
"build": "lerna run build",
"clean": "pnpm run clean:build && pnpm run clean:packages",
"clean:build": "pnpm dlx rimraf packages/*/dist docs/.next",
"clean:packages": "pnpm run lerna clean -y",
"clean:test": "pnpm dlx rimraf tests/tmp/*.{js,js.map,css,html}",
"coverage": "vitest run --coverage",
"eslint": "eslint",
"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 run eslint || true",
"precoverage": "pnpm run build && pnpm run eslint",
"postcoverage": "pnpm run clean:test",
"pretest": "pnpm run build && pnpm run 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 @@ -53,26 +51,29 @@
"@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:*",
"@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",
"copyfiles": "2.4.1",
"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",
"tsup": "6.5.0",
"typescript": "4.9.3",
"vitest": "0.25.3"
},
"lint-staged": {
"*.js": [
"*.ts": [
"prettier --write",
"git add"
]
Expand All @@ -87,18 +88,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
27 changes: 22 additions & 5 deletions packages/babel-minify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-minify/babel-minify",
"version": "7.0.0",
"version": "8.0.2-beta.0",
"description": "babel-minify plugin for @node-minify",
"keywords": [
"compressor",
Expand All @@ -11,16 +11,23 @@
"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__"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"files": [
"lib"
"dist/**/*"
],
"publishConfig": {
"access": "public"
Expand All @@ -32,9 +39,19 @@
"bugs": {
"url": "https://github.com/srod/node-minify/issues"
},
"scripts": {
"clean": "pnpm dlx rimraf dist",
"build": "pnpm clean && tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
"prepublishOnly": "pnpm 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,11 @@
import { transform } from 'babel-core';
import minify from 'babel-preset-minify';
import { utils } from '@node-minify/utils';
import { MinifierOptions } from '@node-minify/types';

interface BabelOptions {
presets: string[];
}

/**
* Run babel-minify.
Expand All @@ -18,16 +23,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 +41,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 +54,5 @@ const minifyBabel = ({ settings, content, callback, index }) => {
/**
* Expose `minifyBabel()`.
*/
module.exports = minifyBabel;
minifyBabel.default = minifyBabel;
export = minifyBabel;
45 changes: 0 additions & 45 deletions packages/clean-css/__tests__/clean-css.test.js

This file was deleted.

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

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;

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', (): 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();

done();
};

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