Skip to content

Commit 11766e3

Browse files
committed
Working intellisense in ESM
1 parent 8ef3584 commit 11766e3

12 files changed

+157
-133
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# Created by git when using merge tools for conflicts
1111
*.BACKUP.*
1212
*.BASE.*
13+
!tsconfig.base*
1314
*.LOCAL.*
1415
*.REMOTE.*
1516
*_BACKUP_*.txt
@@ -395,3 +396,4 @@ $RECYCLE.BIN/
395396
*.lnk
396397

397398
# End of https://www.gitignore.io/api/git,node,linux,macos,python,pycharm,windows,visualstudiocode
399+
build*/

__tests__/replace.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { replace } from '@/replacer.js';
12
import fc, { Arbitrary } from 'fast-check';
2-
import { replace } from '../src/replacer.js';
33

44
const EachSimpleType = [
55
['string', fc.string()],

__tests__/tsconfig.json

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
// Typescript config for tests
1+
// Fake config to satisfy the vscode intellisense
22
{
3-
"extends": "../tsconfig.json",
3+
"extends": "./tsconfig.test.json",
44
"compilerOptions": {
5-
"rootDir": "../",
6-
"types": ["jest", "node"],
7-
"composite": true,
8-
"allowJs": true,
9-
"sourceMap": true,
5+
"composite": false,
106
},
11-
"references": [{ "path": "../src/" }],
12-
"include": [
13-
"./**/*",
14-
"./*",
15-
"../jest*.ts",
16-
"../tsconfig.aliases.json",
17-
"../package.json",
18-
],
7+
"include": ["./**/*", "../src/**/*"],
8+
"exclude": ["node_modules"],
199
}

__tests__/tsconfig.test.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Typescript config for tests
2+
{
3+
"extends": "../tsconfig.base.json",
4+
"compilerOptions": {
5+
"rootDir": "../",
6+
"types": ["jest", "node"],
7+
"composite": true,
8+
"allowJs": true,
9+
"sourceMap": true,
10+
},
11+
"references": [{ "path": "../src/tsconfig.base.json" }],
12+
"include": [
13+
"./**/*",
14+
"./*",
15+
"../jest*.ts",
16+
"../tsconfig.aliases.json",
17+
"../package.json",
18+
"../src/server.test.ts",
19+
],
20+
"exclude": ["node_modules"],
21+
}

jest.config.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const pathAliases = {
1515

1616
// See here for more info https://kulshekhar.github.io/ts-jest/docs/getting-started/presets/#advanced
1717
const preset = createDefaultEsmPreset({
18-
tsconfig: './__tests__/tsconfig.json',
18+
tsconfig: './__tests__/tsconfig.test.json',
1919
});
2020

2121
const config: JestConfigWithTsJest = {
@@ -27,19 +27,22 @@ const config: JestConfigWithTsJest = {
2727
}),
2828
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/build/'],
2929
testRegex: [
30-
'/tests/.*tests?.[jt]sx?',
31-
'/__tests__/.*tests?.[jt]sx?',
32-
'.*.(spec|test).[jt]sx?',
30+
'/tests/.*tests?.[mc]?[jt]sx?$',
31+
'/__tests__/.*tests?.[mc]?[jt]sx?$',
32+
'.*.(spec|test).[mc]?[jt]sx?$',
3333
],
3434
// I dono't think we need to run the spec multiple times.. the functional test on tests/ maybe.
3535
// We can change this back if we consider it useful to run the spec tests when the code is transpiled to javascript
3636
testPathIgnorePatterns: [
3737
'node_modules',
38-
'<rootDir>/build/',
38+
'<rootDir>/build[^/]*/',
3939
'<rootDir>/dist/',
4040
],
4141
testEnvironment: 'node',
42-
collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'],
42+
collectCoverageFrom: [
43+
'src/**/*.{js,ts,jsx,tsx}',
44+
'!src/**/*.{spec,test}.{js,ts,jsx,tsx}',
45+
],
4346
verbose: true,
4447
// Important to use the AfterEnv to have the jest timeout and all the other settings inside that file to be correctly understood
4548
// See the difference between setupFiles and setupFilesAfterEnv to see the difference.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
"start": "npm run build && node . serve",
3232
"build:prod:esm": "tsc --build tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
3333
"build:prod:cjs": "tsc --build tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json && cp package.cjs-template.json dist/cjs/package.json",
34-
"build": "npm run build:debug",
35-
"build:debug": "tsc && tsc --build ./__tests__/tsconfig.json",
34+
"build:debug": "tsc --build ./__tests__/tsconfig.test.json && tsc --build ./src/tsconfig.test.json",
3635
"build:prod": "npm run build:prod:esm && npm run build:prod:cjs",
3736
"watch": "tsc-watch --onSuccess 'node .'",
3837
"lint": "eslint .",

__tests__/server.test.ts renamed to src/server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { serverFactory } from '@/server.js';
21
import type { Server } from 'http';
32
import request from 'supertest';
3+
import { serverFactory } from './server.js';
44
if (process.env.liveUrl) {
55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
66
//@ts-ignore this enables connection to a live server and verify the app
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
2-
"extends": "../tsconfig.json",
2+
"extends": "../tsconfig.base.json",
33
"compilerOptions": {
44
"rootDir": "../",
55
"types": ["node"],
66
"composite": true,
7-
"allowJs": true,
8-
"sourceMap": true,
97
},
108
"include": ["./**/*", "./*"],
11-
"exclude": ["node_modules"],
129
}

src/tsconfig.test.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "../__tests__/tsconfig.json",
3+
"include": ["../src/**/*.spec.ts", "../src/**/*.test.ts"],
4+
"exclude": ["node_modules"],
5+
}

tsconfig.base.json

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"extends": "./tsconfig.aliases.json",
3+
"compilerOptions": {
4+
/* Basic Options */
5+
// "incremental": true, /* Enable incremental compilation */
6+
"target": "ESNext",
7+
/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
8+
"module": "nodenext",
9+
"moduleResolution": "nodenext",
10+
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
11+
"lib": [
12+
/* Specify library files to be included in the compilation. */
13+
"ES2015",
14+
"ES2016",
15+
"ES2017",
16+
"ES2018",
17+
"ES2019",
18+
"ES2020",
19+
"ES2021",
20+
"ES2022",
21+
],
22+
"noImplicitOverride": true,
23+
"checkJs": true /* Report errors in .js files. */,
24+
"declaration": true,
25+
/* Generates corresponding '.d.ts' file. */
26+
"declarationMap": true,
27+
/* Generates a sourcemap for each corresponding '.d.ts' file. */
28+
"sourceMap": true /* Generates corresponding '.map' file. */,
29+
"outDir": "./build",
30+
/* Redirect output structure to the directory. */
31+
"rootDir": ".",
32+
33+
/* Strict Type-Checking Options */
34+
"strict": true,
35+
/* Enable all strict type-checking options. */
36+
"noImplicitAny": true,
37+
/* Raise error on expressions and declarations with an implied 'any' type. */
38+
"strictNullChecks": true,
39+
/* Enable strict null checks. */
40+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
41+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
42+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
43+
"noImplicitThis": true,
44+
/* Raise error on 'this' expressions with an implied 'any' type. */
45+
"alwaysStrict": true,
46+
/* Parse in strict mode and emit "use strict" for each source file. */
47+
48+
/* Additional Checks */
49+
// "noUnusedLocals": true, /* Report errors on unused locals. */
50+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
51+
"noImplicitReturns": true,
52+
/* Report error when not all code paths in function return a value. */
53+
"noFallthroughCasesInSwitch": true,
54+
/* Report errors for fallthrough cases in switch statement. */
55+
"resolveJsonModule": true,
56+
//"keyofStringsOnly": true, // We don't have symbol keys for objects, so this will simplify our code...
57+
58+
/* Module Resolution Options */
59+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
60+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
61+
// "paths": {
62+
// "<rootDir>/package.json":["./package.json"]
63+
// }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
64+
"rootDirs": [] /* List of root folders whose combined content represents the structure of the project at runtime. */,
65+
// "typeRoots": ["./types", "./node_modules/@types"], /* List of folders to include type definitions from. */
66+
"types": ["node"],
67+
/* Type declaration files to be included in compilation. */
68+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
69+
"esModuleInterop": true,
70+
/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
71+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
72+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
73+
74+
/* Source Map Options */
75+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
76+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
77+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
78+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
79+
80+
/* Experimental Options */
81+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
82+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
83+
84+
/* Advanced Options */
85+
"forceConsistentCasingInFileNames": true,
86+
/* Disallow inconsistently-cased references to the same file. */
87+
},
88+
"include": ["./**/*"],
89+
"exclude": [
90+
"node_modules",
91+
"./dist/",
92+
"./build/",
93+
"./build-*/",
94+
"./**/*.spec.ts",
95+
"./**/*.test.ts",
96+
],
97+
"references": [
98+
{ "path": "./__tests__/tsconfig.test.json" },
99+
{ "path": "./src/tsconfig.base.json" },
100+
{ "path": "./src/tsconfig.test.json" },
101+
],
102+
"ts-node": {
103+
// Runtime help for ts-node
104+
"require": ["tsconfig-paths/register"],
105+
"esm": true,
106+
},
107+
}

0 commit comments

Comments
 (0)