Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Refactor imports with directory support
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Feb 21, 2017
1 parent 4156a2a commit bee913a
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 239 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"build": "rimraf dist && tsc",
"dependency-check": "dependency-check . --unused --no-dev && dependency-check . --missing --no-dev",
"test-spec": "ts-node node_modules/blue-tape/bin/blue-tape.js \"src/**/*.spec.ts\" | tap-diff",
"test-cov": "ts-node node_modules/istanbul/lib/cli.js cover -e .ts --print none -x \"*.d.ts\" -x \"*.spec.ts\" node_modules/blue-tape/bin/blue-tape.js -- \"src/**/*.spec.ts\" | tap-diff",
"test-cov": "ts-node node_modules/istanbul/lib/cli.js cover -e .ts --print none -x \"*.d.ts\" -x \"*.spec.ts\" node_modules/blue-tape/bin/blue-tape.js -- \"src/**/*.spec.ts\"",
"test": "npm run build && npm run dependency-check && npm run test-cov && npm run lint",
"bootstrap": "npm install shelljs && node scripts/bootstrap.js",
"prepublish": "node scripts/prepublish.js"
Expand Down Expand Up @@ -84,7 +84,7 @@
"shelljs": "^0.7.0",
"tap-diff": "^0.1.1",
"ts-node": "^2.0.0",
"tslint": "^4.0.2",
"tslint-config-standard": "^3.0.0"
"tslint": "^4.4.2",
"tslint-config-standard": "^4.0.0"
}
}
4 changes: 2 additions & 2 deletions src/bundle.spec.ts
Expand Up @@ -27,14 +27,14 @@ test('bundle', t => {
t.equal(contents, [
`// Generated by typings`,
`// Source: custom_typings/test.d.ts`,
`declare module \'~example~test\' {`,
`declare module \'~example~test/test\' {`,
`export function test (): string;`,
`}`,
``,
`// Generated by typings`,
`// Source: index.d.ts`,
`declare module \'example\' {`,
`export { test } from \'~example~test\'`,
`export { test } from \'~example~test/test\'`,
`}`,
''
].join('\n'))
Expand Down
Expand Up @@ -2,7 +2,7 @@
"name": "test",
"main": "index.js",
"browser": {
"./imported.js": "dep"
"./imported/index.js": "dep"
},
"dependencies": {
"dep": "0.0.0"
Expand Down
37 changes: 19 additions & 18 deletions src/lib/compile.spec.ts
Expand Up @@ -104,7 +104,7 @@ test('compile', t => {
'',
`// Generated by typings`,
`// Source: __test__/fixtures/compile/a/typed.d.ts`,
'declare module \'~root~a\' {',
'declare module \'~root~a/typed\' {',
'import { isDep } from \'~root~a~dep/path\'',
'',
'export interface ITest {',
Expand All @@ -117,7 +117,7 @@ test('compile', t => {
'',
`// Generated by typings`,
`// Source: __test__/fixtures/compile/typings/b.d.ts`,
'declare module \'~root~b/b\' {',
'declare module \'~root~b/b/typings/b\' {',
'export const foo: number',
'}',
'',
Expand All @@ -133,8 +133,8 @@ test('compile', t => {
`// Generated by typings`,
`// Source: __test__/fixtures/compile/root.d.ts`,
'declare module \'~root/root\' {',
'import a from \'~root~a\'',
'import b = require(\'~root~b/b\')',
'import a from \'~root~a/typed\'',
'import b = require(\'~root~b/b/typings/b\')',
'export * from \'~root/root.import\'',
'export default a',
'}',
Expand All @@ -152,13 +152,13 @@ test('compile', t => {
t.equal(out.results.browser, [
`// Generated by typings`,
`// Source: __test__/fixtures/compile/a/typed.browser.d.ts`,
'declare module \'~root~a\' {',
'declare module \'~root~a/typed.browser\' {',
'export function browser (): boolean',
'}',
'',
`// Generated by typings`,
`// Source: __test__/fixtures/compile/browser.d.ts`,
'declare module \'~root~browser\' {',
'declare module \'~root~browser/browser\' {',
'export const bar: boolean',
'}',
'',
Expand All @@ -174,8 +174,8 @@ test('compile', t => {
`// Generated by typings`,
`// Source: __test__/fixtures/compile/root.d.ts`,
'declare module \'~root/root\' {',
'import a from \'~root~a\'',
'import b = require(\'~root~browser\')',
'import a from \'~root~a/typed.browser\'',
'import b = require(\'~root~browser/browser\')',
'export * from \'~root/root.import\'',
'export default a',
'}',
Expand Down Expand Up @@ -316,13 +316,10 @@ test('compile', t => {
'declare module \'~test~foo/index\' {',
'export * from \'~test~foo/x\'',
'}',
'declare module \'~test~foo\' {',
'export * from \'~test~foo/index\';',
'}',
'',
'declare module \'test\' {',
'import * as x from \'~test~foo/x\'',
'export * from \'~test~foo\'',
'export * from \'~test~foo/index\'',
'}',
''
].join('\n'))
Expand Down Expand Up @@ -694,15 +691,15 @@ test('compile', t => {
})
.then(out => {
t.equal(out.results.main, [
'declare module \'~main/imported\' {',
'declare module \'~main/imported/index\' {',
'export function isNotDep (): boolean;',
'}',
'declare module \'main/imported\' {',
'export * from \'~main/imported\';',
'declare module \'main/imported/index\' {',
'export * from \'~main/imported/index\';',
'}',
'',
'declare module \'~main/index\' {',
'export * from \'~main/imported\'',
'export * from \'~main/imported/index\'',
'}',
'declare module \'main/index\' {',
'export * from \'~main/index\';',
Expand All @@ -714,12 +711,12 @@ test('compile', t => {
].join('\n'))

t.equal(out.results.browser, [
'declare module \'~main~dep\' {',
'declare module \'~main~dep/index\' {',
'export function isDep (): boolean;',
'}',
'',
'declare module \'~main/index\' {',
'export * from \'~main~dep\'',
'export * from \'~main~dep/index\'',
'}',
'declare module \'main/index\' {',
'export * from \'~main/index\';',
Expand Down Expand Up @@ -753,6 +750,10 @@ test('compile', t => {
.matchHeader('User-Agent', /^typings\/\d+\.\d+\.\d+ node\/v\d+\.\d+\.\d+.*$/)
.reply(200, 'export * from "./test"')

nock('http://example.com')
.get('/test?query=test')
.reply(404)

nock('http://example.com')
.get('/test.d.ts?query=test')
.reply(200, 'export const test: boolean')
Expand Down

0 comments on commit bee913a

Please sign in to comment.