Skip to content

refactor: port load to typescript #786

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

Merged
merged 19 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion @commitlint/cli/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env node
require('babel-polyfill'); // eslint-disable-line import/no-unassigned-import

const load = require('@commitlint/load');
// fix: commitlint load is ported to typescript, until this one is ported we need to unpack it
const {default: load} = require('@commitlint/load');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This amounts to a breaking change for CommonJS consumers. Can we emit the module to contain the module.exports = ... stanza instead? If i remember correctly there was a tsc settings for this...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it out!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't fix the breakage for external CommonJS consumers but we can use the default import interop babel provides.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should create a building library that works like bob. With such a tool we can build commonjs, module and just typescript definition files. I think that might be best to keep support for all platforms, right? Internally, we can just use the latest default module system.

const lint = require('@commitlint/lint');
const read = require('@commitlint/read');
const meow = require('meow');
Expand Down
39 changes: 6 additions & 33 deletions @commitlint/load/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,13 @@
"version": "8.1.0",
"description": "Load shared commitlint configuration",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/"
],
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"deps": "dep-check",
"pkg": "pkg-check --skip-import",
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
"test": "ava -c 4 --verbose && ava \"src/*.serial-test.js\" --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"files": [
"src/**/*.test.js",
"!lib/**/*"
],
"source": [
"src/**/*.js",
"!lib/**/*"
],
"babel": "inherit",
"require": [
"babel-register"
]
},
"babel": {
"presets": [
"babel-preset-commitlint"
]
"pkg": "pkg-check --skip-import"
},
"engines": {
"node": ">=4"
Expand All @@ -58,19 +36,14 @@
"devDependencies": {
"@commitlint/test": "8.0.0",
"@commitlint/utils": "^8.1.0",
"ava": "0.22.0",
"babel-cli": "6.26.0",
"babel-preset-commitlint": "^8.0.0",
"babel-register": "6.26.0",
"concurrently": "3.6.1",
"cross-env": "5.1.1",
"execa": "0.11.0",
"globby": "10.0.1"
"@types/cosmiconfig": "5.0.3",
"@types/lodash": "4.14.136",
"@types/resolve-from": "^5.0.1",
"typescript": "3.5.3"
},
"dependencies": {
"@commitlint/execute-rule": "^8.1.0",
"@commitlint/resolve-extends": "^8.1.0",
"babel-runtime": "^6.23.0",
"chalk": "2.4.2",
"cosmiconfig": "^5.2.0",
"lodash": "4.17.14",
Expand Down
19 changes: 0 additions & 19 deletions @commitlint/load/src/index.serial-test.js

This file was deleted.

21 changes: 21 additions & 0 deletions @commitlint/load/src/index.serial.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as path from 'path';
import load from '.';

const {fix} = require('@commitlint/test');

const fixture = (name: string) => path.resolve(__dirname, '../fixtures', name);

test('default cwd option to process.cwd()', async () => {
const cwd = await fix.bootstrap(fixture('basic'));
const before = process.cwd();
process.chdir(cwd);

try {
const actual = await load();
expect(actual.rules.basic).toBeTruthy();
} catch (err) {
throw err;
} finally {
process.chdir(before);
}
});
Loading