diff --git a/cjs/index.js b/cjs/index.js index d37d85d..29130b9 100644 --- a/cjs/index.js +++ b/cjs/index.js @@ -1,6 +1,6 @@ const Fastify = require("fastify"); const { fastify } = require("fastify"); -const { default: fastifiDefault } = require("fastify"); +const { default: fastifyDefault } = require("fastify"); const fastify1 = Fastify(); @@ -26,7 +26,7 @@ fastify2 process.exit(1); }); -const fastify3 = fastifiDefault(); +const fastify3 = fastifyDefault(); fastify2 .listen(3002) diff --git a/package.json b/package.json index 17f2098..ba4bf2a 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,12 @@ "description": "", "main": "index.js", "scripts": { - "cjs": "node ./cjs", - "esm": "node ./esm/index.mjs", - "ts-interop-false": "tsc -p ./typescript/es-module-interop-false/tsconfig.json && node ./typescript/es-module-interop-false/build", - "ts-interop-true": "tsc -p ./typescript/es-module-interop-true/tsconfig.json && node ./typescript/es-module-interop-true/build", - "all": "run-p cjs esm ts-interop-false ts-interop-true" + "run:cjs": "node ./cjs", + "run:esm": "node ./esm/index.mjs", + "run:ts-interop-false": "tsc -p ./typescript/es-module-interop-false/tsconfig.json && node ./typescript/es-module-interop-false/build", + "run:ts-interop-true": "tsc -p ./typescript/es-module-interop-true/tsconfig.json && node ./typescript/es-module-interop-true/build", + "run:typed-cjs": "tsc -p ./typed-cjs/tsconfig.json && node ./cjs", + "all": "run-p run:*" }, "repository": { "type": "git", diff --git a/typed-cjs/index.js b/typed-cjs/index.js new file mode 100644 index 0000000..29130b9 --- /dev/null +++ b/typed-cjs/index.js @@ -0,0 +1,39 @@ +const Fastify = require("fastify"); +const { fastify } = require("fastify"); +const { default: fastifyDefault } = require("fastify"); + +const fastify1 = Fastify(); + +fastify1 + .listen(3000) + .then(() => { + console.log(`[CJS] module.exports is running.`); + }) + .catch((err) => { + console.log(err); + process.exit(1); + }); + +const fastify2 = fastify(); + +fastify2 + .listen(3001) + .then(() => { + console.log(`[CJS] named require is running.`); + }) + .catch((err) => { + console.log(err); + process.exit(1); + }); + +const fastify3 = fastifyDefault(); + +fastify2 + .listen(3002) + .then(() => { + console.log(`[CJS] default property require is running.`); + }) + .catch((err) => { + console.log(err); + process.exit(1); + }); diff --git a/typed-cjs/tsconfig.json b/typed-cjs/tsconfig.json new file mode 100644 index 0000000..d23292b --- /dev/null +++ b/typed-cjs/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "noEmit": true, + }, + "include": [ + "./index.js" + ] +} \ No newline at end of file