-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from voxpelli/self-hosted
Self host types to enable experimentation
- Loading branch information
Showing
32 changed files
with
320 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,4 +102,4 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
package-lock.json | ||
package-lock.json |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const helloWorld = require("../"); | ||
// Non-supported | ||
// const { helloWorld: namedHelloWorld } = require("../"); | ||
// const { default: defaultHelloWorld } = require("../"); | ||
|
||
if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// Non-supported | ||
// if (namedHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// if (defaultHelloWorld() !== 'Hello World') throw new Error('Oh no!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export = helloWorld; | ||
|
||
declare namespace helloWorld { | ||
type HelloWorldResponse = 'Hello World'; | ||
} | ||
|
||
declare function helloWorld(): helloWorld.HelloWorldResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const helloWorld = () => 'Hello World'; | ||
|
||
/** | ||
* These export configurations enable JS and TS developers | ||
* to consumer fastify in whatever way best suits their needs. | ||
* Some examples of supported import syntax includes: | ||
* - `const helloWorld = require('./triplet')` | ||
* - `const { helloWorld } = require('./triplet')` | ||
* - `import * as HelloWorld from './triplet'` | ||
* - `import { helloWorld, TSC_definition } from './triplet'` | ||
* - `import helloWorld from './triplet'` | ||
* - `import helloWorld, { TSC_definition } from './triplet'` | ||
*/ | ||
module.exports = helloWorld | ||
module.exports.helloWorld = helloWorld | ||
module.exports.default = helloWorld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const helloWorld = require("../"); | ||
// Non-supported | ||
// const { helloWorld: namedHelloWorld } = require("../"); | ||
// const { default: defaultHelloWorld } = require("../"); | ||
|
||
/** @type {import('../').HelloWorldResponse} */ | ||
const desiredResult = 'Hello World'; | ||
|
||
if (helloWorld() !== desiredResult) throw new Error('Oh no!'); | ||
// Non-supported | ||
// if (namedHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// if (defaultHelloWorld() !== 'Hello World') throw new Error('Oh no!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ | |
"noEmit": true, | ||
}, | ||
"include": [ | ||
"./index.js" | ||
"index.js", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
index.js |
34 changes: 34 additions & 0 deletions
34
self-hosted-namespace/typescript/es-module-interop-false/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Not supported | ||
// import helloWorld from "../../"; | ||
// import { helloWorld as namedHelloWorld } from "../../"; | ||
// import * as HelloWorldNamespace from "../../"; | ||
import helloWorldRequire = require("../../") | ||
|
||
// Not supported | ||
// if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// if (namedHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// if (HelloWorldNamespace.default() !== 'Hello World') throw new Error('Oh no!'); | ||
if (helloWorldRequire() !== 'Hello World') throw new Error('Oh no!'); | ||
|
||
// Not supported | ||
// import("../../") | ||
// .then(({ | ||
// default: defaultHelloWorld, | ||
// helloWorld | ||
// }) => { | ||
// if (defaultHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// }) | ||
// .catch((err) => { | ||
// console.log(err); | ||
// process.exit(1); | ||
// }); | ||
|
||
import("../../") | ||
.then((helloWorld) => { | ||
if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
process.exit(1); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...ipt/es-module-interop-false/tsconfig.json → ...ipt/es-module-interop-false/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
self-hosted-namespace/typescript/es-module-interop-true/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import helloWorld from "../../"; | ||
// Not supported | ||
// import { helloWorld as namedHelloWorld } from "../../"; | ||
// import * as HelloWorldNamespace from "../../"; | ||
import helloWorldRequire = require("../../") | ||
|
||
if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// Not supported | ||
// if (namedHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// if (HelloWorldNamespace.default() !== 'Hello World') throw new Error('Oh no!'); | ||
if (helloWorldRequire() !== 'Hello World') throw new Error('Oh no!'); | ||
|
||
import("../../") | ||
.then(({ | ||
default: defaultHelloWorld, | ||
// Not supported | ||
// helloWorld | ||
}) => { | ||
if (defaultHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
process.exit(1); | ||
}); | ||
|
||
// Not supported | ||
// import("../../") | ||
// .then((helloWorld) => { | ||
// if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
// }) | ||
// .catch((err) => { | ||
// console.log(err); | ||
// process.exit(1); | ||
// }); |
2 changes: 1 addition & 1 deletion
2
...ript/es-module-interop-true/tsconfig.json → ...ript/es-module-interop-true/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const helloWorld = require("../"); | ||
const { helloWorld: namedHelloWorld } = require("../"); | ||
const { default: defaultHelloWorld } = require("../"); | ||
|
||
if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
if (namedHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
if (defaultHelloWorld() !== 'Hello World') throw new Error('Oh no!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import helloWorld from "../index.js"; | ||
|
||
// we currently dont' support named exports in ESM context | ||
// import { fastify } from "fastify"; | ||
// ^^^^^^^ | ||
// SyntaxError: The requested module 'fastify' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export. | ||
|
||
if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
|
||
// dynamic namespace import is not callable because because this is its shape: | ||
// [Module] { | ||
// default: <ref *1> [Function: fastify] { | ||
// fastify: [Circular *1], | ||
// default: [Circular *1] | ||
// } | ||
// } | ||
// however we can still use its default export | ||
import("../index.js") | ||
.then(({ default: defaultHelloWorld }) => { | ||
if (defaultHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type HelloWorldResponse = 'Hello World'; | ||
|
||
declare function helloWorld(): HelloWorldResponse; | ||
|
||
export default helloWorld; | ||
export { helloWorld } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const helloWorld = () => 'Hello World'; | ||
|
||
/** | ||
* These export configurations enable JS and TS developers | ||
* to consumer fastify in whatever way best suits their needs. | ||
* Some examples of supported import syntax includes: | ||
* - `const helloWorld = require('./triplet')` | ||
* - `const { helloWorld } = require('./triplet')` | ||
* - `import * as HelloWorld from './triplet'` | ||
* - `import { helloWorld, TSC_definition } from './triplet'` | ||
* - `import helloWorld from './triplet'` | ||
* - `import helloWorld, { TSC_definition } from './triplet'` | ||
*/ | ||
module.exports = helloWorld | ||
module.exports.helloWorld = helloWorld | ||
module.exports.default = helloWorld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"skipLibCheck": false, | ||
"pretty": true, | ||
"lib": [ | ||
"esnext" | ||
], | ||
"typeRoots": [ | ||
"../node_modules/@types", | ||
] | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Non-supported | ||
// const helloWorld = require("../"); | ||
const { helloWorld: namedHelloWorld } = require("../"); | ||
const { default: defaultHelloWorld } = require("../"); | ||
|
||
// Non-supported | ||
// if (helloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
if (namedHelloWorld() !== 'Hello World') throw new Error('Oh no!'); | ||
if (defaultHelloWorld() !== 'Hello World') throw new Error('Oh no!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"checkJs": true, | ||
"noEmit": true, | ||
}, | ||
"include": [ | ||
"index.js", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
index.js |
Oops, something went wrong.