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

chore: add scripts to generate dt compatible #233

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3053bcd
chore: add scripts to generate dt compatible definition files
ikatyang Aug 15, 2017
d17a565
chore: fix linting
ikatyang Aug 15, 2017
0419dfd
chore: exit code 1 if dt failed
ikatyang Aug 16, 2017
b5b2cab
chore(deps): update prettier to v1.6.0-dev (github)
ikatyang Aug 16, 2017
e892f91
Merge branch master into 'add-scripts-to-generate-dt-compatible'
ikatyang Aug 16, 2017
f6a9149
chore(tslint): disable ban-types rule for DT
ikatyang Aug 16, 2017
05765a5
Merge branch master into 'add-scripts-to-generate-dt-compatible'
ikatyang Aug 16, 2017
31031cc
refactor: fix linting
ikatyang Aug 16, 2017
8b30c59
Merge branch master into 'add-scripts-to-generate-dt-compatible'
ikatyang Aug 17, 2017
1861445
refactor: fix linting
ikatyang Aug 17, 2017
646bc89
chore: add scripts to generate dt compatible test file
ikatyang Aug 17, 2017
761ef7d
chore: install dtslint before build-dt
ikatyang Aug 17, 2017
456c1b6
chore: update TS version in DT to v2.4
ikatyang Aug 17, 2017
44eea4e
Merge branch master into 'add-scripts-to-generate-dt-compatible'
ikatyang Aug 18, 2017
5e5f97e
chore: enable inline_return_type
ikatyang Aug 18, 2017
0641652
Merge branch master into 'add-scripts-to-generate-dt-compatible'
ikatyang Aug 18, 2017
ab58d5f
Merge branch master into 'add-scripts-to-generate-dt-compatible'
ikatyang Aug 18, 2017
a5d1204
Merge 'master' into add-scripts-to-generate-dt-compatible
ikatyang Sep 4, 2017
64ba173
chore: fix merge conflict
ikatyang Sep 4, 2017
4958093
Merge branch 'master' into add-scripts-to-generate-dt-compatible
ikatyang Sep 4, 2017
4b5d4ee
chore(deps): update typescript to version 2.5.2
ikatyang Sep 4, 2017
60852db
Merge branch 'master' into add-scripts-to-generate-dt-compatible
ikatyang Sep 5, 2017
87ade62
chore(dt): disable enclosing_declaration
ikatyang Sep 5, 2017
5bc3949
refactor: remove unnecessary operation
ikatyang Sep 5, 2017
07c9092
test: update test cases to avoid `console is not defined`
ikatyang Sep 5, 2017
d01f6e9
test: update snapshots
ikatyang Sep 5, 2017
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DefinitelyTyped/yarn.lock
coverage/
node_modules/
ramda/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ script:
- yarn run test -- --ci --testPathPattern='/tests/ramda-tests.ts' --verbose=false
- yarn run test -- --ci --testPathPattern='/tests/[a-z_]+.ts'
- yarn run remap -- --check --list-different
- yarn run test-dt

after_success:
- if [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./scripts/deploy.sh; fi
Expand Down
13 changes: 13 additions & 0 deletions DefinitelyTyped/dt-header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Type definitions for ramda 0.24
// Project: https://github.com/types/npm-ramda
// Definitions by: Erwin Poeze <https://github.com/donnut>
// Matt DeKrey <https://github.com/mdekrey>
// Liam Goodacre <https://github.com/LiamGoodacre>
// Matt Dziuban <https://github.com/mrdziuban>
// Stephen King <https://github.com/sbking>
// Alejandro Fernandez Haro <https://github.com/afharo>
// Vítor Castro <https://github.com/teves-castro>
// Jordan Quagliatini <https://github.com/1M0reBug>
// Simon Højberg <https://github.com/hojberg>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
11 changes: 11 additions & 0 deletions DefinitelyTyped/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"name": "definitely-typed",
"version": "0.0.0-dt",
"scripts": {
"lint": "dtslint types ramda"
},
"devDependencies": {
"dtslint": "Microsoft/dtslint#production"
}
}
15 changes: 15 additions & 0 deletions DefinitelyTyped/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["---auto-generated-from-scripts---"]
}
10 changes: 10 additions & 0 deletions DefinitelyTyped/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false,
"callable-types": false,
"interface-over-type-literal": false,
"unified-signatures": false,
"no-unnecessary-type-assertion": false
}
}
25 changes: 24 additions & 1 deletion gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import * as del from 'del';
import * as gulp from 'gulp';
import * as gulp_run from 'run-sequence';
import {
build_dt_chores,
build_dt_definitions,
build_dt_tests,
} from './tasks/build-dt';
import { build_watch } from './tasks/build-watch';
import { remap_watch } from './tasks/remap-watch';
import {
dt_ramda_dirname,
glob_templates,
output_relative_dirname,
} from './tasks/utils/constants';
Expand All @@ -12,11 +18,13 @@ import { generate_files } from './tasks/utils/generate-files';
import { generate_index } from './tasks/utils/generate-index';
import { generate_remap_content } from './tasks/utils/generate-remap-content';

type RunCallback = (error?: any) => void;

gulp.task('clean', async () => del(`${output_relative_dirname}/`));
gulp.task('build-index', generate_index);
gulp.task('build-files', () => generate_files(glob_templates));

gulp.task('build', ['clean'], (callback: (error?: any) => void) =>
gulp.task('build', ['clean'], (callback: RunCallback) =>
gulp_run(['build-index', 'build-files'], callback),
);

Expand All @@ -31,3 +39,18 @@ gulp.task('remap', ['clean-remap'], () =>
);

gulp.task('remap-watch', ['remap'], remap_watch);

gulp.task('clean-dt', async () => del(dt_ramda_dirname));

gulp.task('build-dt-definitions', build_dt_definitions);
gulp.task('build-dt-chores', build_dt_chores);
gulp.task('build-dt-tests', build_dt_tests);

gulp.task('build-dt', ['clean-dt', 'build'], (callback: RunCallback) =>
gulp_run(
'build-dt-definitions',
'build-dt-chores',
'build-dt-tests',
callback,
),
);
16 changes: 16 additions & 0 deletions jest.dt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"testEnvironment": "node",
"moduleFileExtensions": ["ts", "js", "json"],
"testRegex": "/temp/.+\\.ts$",
"transform": {"/temp/.+\\.ts$": "dts-jest/transform"},
"moduleNameMapper": {
"../ramda/dist": "<rootDir>/node_modules/ramda"
},
"globals": {
"_dts_jest_": {
"enclosing_declaration": false,
"compiler_options": "./tsconfig.test.json",
"typescript": "<cwd>/node_modules/typescript/lib/typescript"
}
}
}
3 changes: 2 additions & 1 deletion jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"globals": {
"_dts_jest_": {
"enclosing_declaration": true,
"compiler_options": "./tsconfig.test.json"
"compiler_options": "./tsconfig.test.json",
"typescript": "<cwd>/node_modules/typescript/lib/typescript"
}
},
"reporters": [
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"build-watch": "gulp build-watch",
"remap": "dts-jest-remap ./tests/*.ts --outDir ./snapshots",
"remap-watch": "gulp remap-watch",
"jsdoc": "ts-node ./scripts/migrate-jsdoc.ts v0.24.1 ./templates"
"jsdoc": "ts-node ./scripts/migrate-jsdoc.ts v0.24.1 ./templates",
"build-dt": "gulp build-dt",
"test-dt": "bash ./scripts/test-dt.sh"
},
"devDependencies": {
"@types/del": "3.0.0",
Expand All @@ -29,6 +31,7 @@
"@types/gulp-util": "3.0.31",
"@types/jest": "20.0.8",
"@types/node": "8.0.26",
"@types/prettier": "1.5.0",
"@types/ramda": "ikatyang/types-ramda#v0.24.1-dist",
"@types/run-sequence": "0.0.29",
"@types/through2": "2.0.33",
Expand All @@ -39,6 +42,8 @@
"dts-jest": "22.0.3",
"glob": "7.1.2",
"gulp": "3.9.1",
"gulp-modify": "0.1.1",
"gulp-plugin-prettier": "1.0.0",
"gulp-rename": "1.2.2",
"gulp-util": "3.0.8",
"jest": "21.0.1",
Expand Down
15 changes: 15 additions & 0 deletions scripts/test-dt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

cd ./DefinitelyTyped
yarn install --force
cd ..

yarn run build-dt

cd ./DefinitelyTyped
yarn run lint || eval "DT_LINT_STATE=error"
cd ..

if [ "$DT_LINT_STATE" = "error" ]; then
exit 1;
fi
8 changes: 4 additions & 4 deletions snapshots/ramda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ import * as R from '../ramda/dist/index';

// @dts-jest:group bind
(() => {
// @dts-jest:pass:snap -> (message?: any, ...optionalParams: any[]) => void
R.bind(console.log, console);
// @dts-jest:pass:snap -> (arg: any) => arg is any[]
R.bind(Array.isArray, Array);
})();

// @dts-jest:group both
Expand Down Expand Up @@ -1503,7 +1503,7 @@ import * as R from '../ramda/dist/index';
// @dts-jest:group lensIndex
(() => {
const headLens = R.lensIndex(0);
// @dts-jest:pass:snap -> any
// @dts-jest:pass:snap -> string
R.view(headLens, ['a', 'b', 'c']); //=> 'a'

// @dts-jest:pass:snap -> string[]
Expand Down Expand Up @@ -3195,7 +3195,7 @@ import * as R from '../ramda/dist/index';
// @dts-jest:group view
(() => {
const headLens = R.lensIndex(0);
// @dts-jest:pass:snap -> any
// @dts-jest:pass:snap -> string
R.view(headLens, ['a', 'b', 'c']); //=> 'a'
})();

Expand Down
6 changes: 3 additions & 3 deletions snapshots/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ R_view(pseudo_lens_a)(a_1_b_2_c_3);
// @dts-jest:pass:snap -> 1
R_view(pseudo_lens_a, a_1_b_2_c_3);

// @dts-jest:pass:snap -> <U extends { [index: number]: any; }>(target: U) => U["1"]
// @dts-jest:pass:snap -> <U extends { [index: number]: any; }>(target: U) => U[1]
R_view(pseudo_lens_1);
// @dts-jest:pass:snap -> number
R_view(pseudo_lens_1)(string_number_tuple);
// @dts-jest:pass:snap -> number
R_view(pseudo_lens_1, string_number_tuple);
// @dts-jest:pass:snap -> any
// @dts-jest:pass:snap -> number
R_view(pseudo_lens_1)(number_array);
// @dts-jest:pass:snap -> any
// @dts-jest:pass:snap -> number
R_view(pseudo_lens_1, number_array);
110 changes: 110 additions & 0 deletions tasks/build-dt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import * as child_process from 'child_process';
import del = require('del');
import * as fs from 'fs';
import * as gulp from 'gulp';
import * as gulp_prettier from 'gulp-plugin-prettier';
import * as gulp_util from 'gulp-util';
import * as prettier from 'prettier';
import * as tslint from 'tslint';
import {
dt_dirname,
dt_ramda_dirname,
output_relative_dirname,
} from './utils/constants';

// tslint:disable-next-line:no-var-requires
const gulp_modify = require('gulp-modify');

const test_filename = 'ramda-tests.ts';

const definition_names: string[] = [];

// DT style (https://github.com/Microsoft/dtslint/blob/master/dt.json)
const prettier_options: prettier.Options = {
bracketSpacing: true,
printWidth: 120, // original 200, decreased due to trailing comments
tabWidth: 4,
trailingComma: 'all',
parser: 'typescript',
};

export const build_dt_definitions = () =>
gulp
.src(`${output_relative_dirname}/**/*`, {
base: output_relative_dirname,
})
.pipe(
gulp_modify({
fileModifier: (file: gulp_util.File, contents: string) => {
definition_names.push(file.relative);
if (file.path.endsWith('index.d.ts')) {
const dt_header = fs
.readFileSync(`${dt_dirname}/dt-header.txt`, 'utf8')
.trim();
return `${dt_header}\n\n${contents}`;
}
return contents;
},
}),
)
.pipe(
gulp_prettier.format(prettier_options, {
reporter: gulp_prettier.Reporter.None,
}),
)
.pipe(gulp.dest(dt_ramda_dirname));

export const build_dt_chores = () =>
gulp
.src([`${dt_dirname}/tsconfig.json`, `${dt_dirname}/tslint.json`])
.pipe(
gulp_modify({
fileModifier: (file: gulp_util.File, contents: string) => {
if (file.path.endsWith('tsconfig.json')) {
const tsconfig = JSON.parse(contents);
tsconfig.files = [...definition_names, test_filename];
return JSON.stringify(tsconfig, null, 4);
}
return contents;
},
}),
)
.pipe(gulp.dest(dt_ramda_dirname));

export const build_dt_tests = () => {
const temp_dirname = 'temp';
const remapped_filename = `${test_filename}.remapped`;

const commands = [
`rm -rf ${temp_dirname}`,
`mkdir ${temp_dirname}`,
`cp tests/${test_filename} ${temp_dirname}/`,
`node_modules/.bin/jest -c ./jest.dt.json -u --silent`,
`node_modules/.bin/dts-jest-remap ${temp_dirname}/${test_filename} --rename ${remapped_filename}`,
];

child_process.execSync(commands.join(' && '));

const linter = new tslint.Linter({ fix: true });

const output_filename = `${dt_ramda_dirname}/${test_filename}`;

const output_content = prettier.format(
fs
.readFileSync(`${temp_dirname}/${remapped_filename}`, 'utf8')
.replace(`'../ramda/dist/index'`, `'ramda'`)
.replace(/\/\/ @dts-jest:fail.+/g, '// $ExpectError')
.replace(/\/\/ @dts-jest:pass:snap ->/g, '// $ExpectType'),
prettier_options,
);

fs.writeFileSync(output_filename, output_content);

linter.lint(
output_filename,
output_content,
tslint.Linter.findConfiguration(null, output_filename).results,
);

del.sync(temp_dirname);
};
3 changes: 3 additions & 0 deletions tasks/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ export const output_sub_dirname = 'src';
export const output_relative_dirname = `./ramda/dist${output_dirname_postfix}`;
export const output_relative_sub_dirname = `${output_relative_dirname}/${output_sub_dirname}`;
export const output_extname = '.d.ts';

export const dt_dirname = 'DefinitelyTyped';
export const dt_ramda_dirname = `${dt_dirname}/types/ramda`;
1 change: 1 addition & 0 deletions tasks/utils/generate-file-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function get_top_level_members(filename: string): dts.ITopLevelMember[] {
{
selectable,
placeholder,
inline_return_type: true,
},
);

Expand Down
5 changes: 0 additions & 5 deletions templates/$operation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ export type Same<T extends string, U extends string> = Diff<
Diff<T, U> | Diff<U, T>
>;
export type Merge<T, U> = Omit<T, keyof U> & U;

// from https://github.com/tycho01/typical/blob/f0e6918/src/cast.ts#L18
// to resolve https://github.com/Microsoft/TypeScript/issues/15768
// tslint:disable-next-line:prettier interface-over-type-literal
export type NumberToString = { 0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',10:'10',11:'11',12:'12',13:'13',14:'14',15:'15',16:'16',17:'17',18:'18',19:'19',20:'20',21:'21',22:'22',23:'23',24:'24',25:'25',26:'26',27:'27',28:'28',29:'29',30:'30',31:'31',32:'32',33:'33',34:'34',35:'35',36:'36',37:'37',38:'38',39:'39',40:'40',41:'41',42:'42',43:'43',44:'44',45:'45',46:'46',47:'47',48:'48',49:'49',50:'50',51:'51',52:'52',53:'53',54:'54',55:'55',56:'56',57:'57',58:'58',59:'59',60:'60',61:'61',62:'62',63:'63',64:'64',65:'65',66:'66',67:'67',68:'68',69:'69',70:'70',71:'71',72:'72',73:'73',74:'74',75:'75',76:'76',77:'77',78:'78',79:'79',80:'80',81:'81',82:'82',83:'83',84:'84',85:'85',86:'86',87:'87',88:'88',89:'89',90:'90',91:'91',92:'92',93:'93',94:'94',95:'95',96:'96',97:'97',98:'98',99:'99',100:'100',101:'101',102:'102',103:'103',104:'104',105:'105',106:'106',107:'107',108:'108',109:'109',110:'110',111:'111',112:'112',113:'113',114:'114',115:'115',116:'116',117:'117',118:'118',119:'119',120:'120',121:'121',122:'122',123:'123',124:'124',125:'125',126:'126',127:'127',128:'128',129:'129',130:'130',131:'131',132:'132',133:'133',134:'134',135:'135',136:'136',137:'137',138:'138',139:'139',140:'140',141:'141',142:'142',143:'143',144:'144',145:'145',146:'146',147:'147',148:'148',149:'149',150:'150',151:'151',152:'152',153:'153',154:'154',155:'155',156:'156',157:'157',158:'158',159:'159',160:'160',161:'161',162:'162',163:'163',164:'164',165:'165',166:'166',167:'167',168:'168',169:'169',170:'170',171:'171',172:'172',173:'173',174:'174',175:'175',176:'176',177:'177',178:'178',179:'179',180:'180',181:'181',182:'182',183:'183',184:'184',185:'185',186:'186',187:'187',188:'188',189:'189',190:'190',191:'191',192:'192',193:'193',194:'194',195:'195',196:'196',197:'197',198:'198',199:'199',200:'200',201:'201',202:'202',203:'203',204:'204',205:'205',206:'206',207:'207',208:'208',209:'209',210:'210',211:'211',212:'212',213:'213',214:'214',215:'215',216:'216',217:'217',218:'218',219:'219',220:'220',221:'221',222:'222',223:'223',224:'224',225:'225',226:'226',227:'227',228:'228',229:'229',230:'230',231:'231',232:'232',233:'233',234:'234',235:'235',236:'236',237:'237',238:'238',239:'239',240:'240',241:'241',242:'242',243:'243',244:'244',245:'245',246:'246',247:'247',248:'248',249:'249',250:'250',251:'251',252:'252',253:'253',254:'254',255:'255'};
3 changes: 1 addition & 2 deletions templates/over.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NumberToString } from './$operation';
import { ManualLens, Morphism, PseudoLens } from './$types';

export function $number<N extends number, U extends { [index: number]: any }>(
lens: PseudoLens<N>,
fn: Morphism<U[NumberToString[N]], U[NumberToString[N]]>,
fn: Morphism<U[N], U[N]>,
target: U,
): U;
export function $string<K extends string, U extends Record<K, any>>(
Expand Down
3 changes: 1 addition & 2 deletions templates/set.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NumberToString } from './$operation';
import { ManualLens, PseudoLens } from './$types';

export function $number<N extends number, U extends { [index: number]: any }>(
lens: PseudoLens<N>,
value: U[NumberToString[N]],
value: U[N],
target: U,
): U;
export function $string<K extends string, U extends Record<K, any>>(
Expand Down
6 changes: 6 additions & 0 deletions templates/tslint.dts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tslint.json",
"rules": {
"naming-convention": false
}
}
Loading