From 9a971c822e691cd5f26002d51ad8234bcf8a67c5 Mon Sep 17 00:00:00 2001 From: teppeis Date: Sun, 2 Jul 2017 21:46:49 +0900 Subject: [PATCH 1/2] fix: support `types` option with TypeScript 2.4.1 --- .circleci/config.yml | 68 ++++++++++++++++++++++++++++++++++++++++++++ index.ts | 17 ++++++++++- package-lock.json | 12 ++++---- package.json | 2 +- test/.eslintrc.json | 5 ++++ test/test.js | 7 +++++ 6 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 test/.eslintrc.json diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..981154f --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,68 @@ +workflows: + version: 2 + node-multi-build: + jobs: + - node-v4 + - node-v6 + - node-v8 + +version: 2 +jobs: + node-base: &node-base + docker: + - image: node + environment: + working_directory: ~/working_directory + steps: + - run: + name: Versions + command: | + yarn versions + echo "npm: $(npm --version)" + - checkout + - restore_cache: + keys: + - v{{ .Environment.CIRCLE_CACHE_VERSION }}-npm-lock-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }} + - v{{ .Environment.CIRCLE_CACHE_VERSION }}-npm-lock-master-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }} + - v{{ .Environment.CIRCLE_CACHE_VERSION }}-npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }} + - v{{ .Environment.CIRCLE_CACHE_VERSION }}-npm-cache-master-{{ .Environment.CIRCLE_JOB }} + - run: + name: Install dependencies + command: npm install + - run: + name: Test with TypeScript 2.2 + command: | + npm install --no-save typescript@2.2 + npm test + - run: + name: Test with TypeScript 2.3 + command: | + npm install --no-save typescript@2.3 + npm test + - run: + name: Test with TypeScript 2.4 + command: | + npm install --no-save typescript@2.4 + npm test + - save_cache: + key: v{{ .Environment.CIRCLE_CACHE_VERSION }}-npm-lock-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }} + paths: + - node_modules + - save_cache: + key: v{{ .Environment.CIRCLE_CACHE_VERSION }}-npm-cache-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }} + paths: + - /usr/local/share/.cache/yarn + - ~/.npm/_cacache + + node-v4: + <<: *node-base + docker: + - image: node:4 + node-v6: + <<: *node-base + docker: + - image: node:6 + node-v8: + <<: *node-base + docker: + - image: node:8 diff --git a/index.ts b/index.ts index 2f312f1..0bdeb4e 100644 --- a/index.ts +++ b/index.ts @@ -114,9 +114,24 @@ namespace tss { getNewLine: () => os.EOL, log: (message: string) => console.log(message), trace: (message: string) => console.debug(message), - error: (message: string) => console.error(message) + error: (message: string) => console.error(message), + readFile: readFile, + fileExists: fileExists }; + function readFile(filename: string, encoding?: string): string { + try { + const content = fs.readFileSync(filename, encoding || 'utf8'); + return content; + } catch (e) { + return ''; + } + } + + function fileExists(filename: string): boolean { + return readFile(filename) !== ''; + } + return ts.createLanguageService(serviceHost, ts.createDocumentRegistry()) } diff --git a/package-lock.json b/package-lock.json index b720c09..4399710 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,9 +4,9 @@ "lockfileVersion": 1, "dependencies": { "@types/node": { - "version": "7.0.31", - "resolved": "https://registry.npmjs.org/@types/node/-/node-7.0.31.tgz", - "integrity": "sha512-+KrE1LDddn97ip+gXZAnzNQ0pupKH/6tcKwTpo96BDVNpzmhIKGHug0Wd3H0dN4WEqYB1tXYI5m2mZuIZNI8tg==", + "version": "8.0.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.7.tgz", + "integrity": "sha512-fuCPLPe4yY0nv6Z1rTLFCEC452jl0k7i3gF/c8hdEKpYtEpt6Sk67hTGbxx8C0wmifFGPvKYd/O8CvS6dpgxMQ==", "dev": true }, "balanced-match": { @@ -175,9 +175,9 @@ "dev": true }, "typescript": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.4.0.tgz", - "integrity": "sha1-rvWo1AS+ujatM5q/B53d3/+6ht0=" + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.4.1.tgz", + "integrity": "sha1-w8yxbdqgsjFN4DHn5v7onlujRrw=" }, "wrappy": { "version": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index e9a5263..03bbc92 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "typescript": "^2.2.1" }, "devDependencies": { - "@types/node": "^7.0.31", + "@types/node": "^8.0.7", "mocha": "^3.1.2" }, "homepage": "https://github.com/teppeis/typescript-simple", diff --git a/test/.eslintrc.json b/test/.eslintrc.json new file mode 100644 index 0000000..4668ae7 --- /dev/null +++ b/test/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "env": { + "mocha": true + } +} diff --git a/test/test.js b/test/test.js index a423719..a97381e 100644 --- a/test/test.js +++ b/test/test.js @@ -266,4 +266,11 @@ describe('typescript-simple', function() { assert.equal(tss.compile(src, path.join(__dirname, 'module.ts')), expected); assert.equal(tss.compile(src, path.join('test', 'module.ts')), expected); }); + + it('compiles correct source with `types`', function() { + var tss = new TypeScriptSimple({types: ['node']}); + var src = "var x: number = 1;"; + var expected = 'var x = 1;' + eol; + assert.equal(tss.compile(src), expected); + }); }); From 6e97d29c7731f93998fdb22b8c74a02088dbecef Mon Sep 17 00:00:00 2001 From: teppeis Date: Sun, 2 Jul 2017 21:57:11 +0900 Subject: [PATCH 2/2] ci: disable travis-ci --- .travis.yml | 9 --------- README.md | 4 +++- appveyor.yml | 5 +++++ 3 files changed, 8 insertions(+), 10 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9e6daef..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: node_js -node_js: - - "4" - - "6" - - "8" -sudo: false -cache: - directories: - - node_modules diff --git a/README.md b/README.md index 18c8377..0bcbe7b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Simple API to compile TypeScript code string to JavaScript. That's all! [![npm version][npm-image]][npm-url] [![npm downloads][npm-downloads-image]][npm-url] ![Node.js Version Support][node-version] -[![build status][travis-image]][travis-url] +[![build status][circleci-image]][circleci-url] [![windows build status][appveyor-image]][appveyor-url] [![dependency status][deps-image]][deps-url] ![License][license] @@ -156,3 +156,5 @@ MIT License: Teppei Sato <teppeis@gmail.com> [license]: https://img.shields.io/npm/l/typescript-simple.svg [appveyor-image]: https://ci.appveyor.com/api/projects/status/22nwyfaf5p0yw54j/branch/master?svg=true [appveyor-url]: https://ci.appveyor.com/project/teppeis/typescript-simple/branch/master +[circleci-image]: https://circleci.com/gh/teppeis/typescript-simple.svg?style=svg +[circleci-url]: https://circleci.com/gh/teppeis/typescript-simple diff --git a/appveyor.yml b/appveyor.yml index ce32034..18d3f47 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,6 +20,11 @@ test_script: - node --version - npm --version # run tests + - npm install --no-save typescript@2.2 + - npm test + - npm install --no-save typescript@2.3 + - npm test + - npm install --no-save typescript@2.4 - npm test # Don't actually build.