Skip to content

Commit 1fb9cd1

Browse files
committed
Correct line numbers in source maps
1 parent 800fcd4 commit 1fb9cd1

File tree

4 files changed

+124
-85
lines changed

4 files changed

+124
-85
lines changed

src/main/resources/static/tsconfig.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
{
1+
{ // https://www.typescriptlang.org/tsconfig
22
"compilerOptions": {
33
"baseUrl": ".",
4+
"declaration": false,
45
"esModuleInterop": true, // Needed for the 'q' npm module
5-
"module": "commonjs",
6+
"forceConsistentCasingInFileNames": true,
7+
8+
// Set in tsup/static.ts instead
9+
// "inlineSourceMap": true,
10+
// "inlineSources": true,
11+
12+
// TODO: Is this the line that caused wrong line numbers?
13+
// "module": "commonjs",
14+
615
"lib": [
716
"DOM",
817
"ES2020",
@@ -12,14 +21,23 @@
1221
"paths": {},
1322
"rootDir": ".",
1423
"skipLibCheck": true,
15-
"target": "es5", // Modern browsers
24+
25+
// Set in tsup/static.ts instead
26+
// "sourceMap": true, // Important to get correct line numbers?
27+
28+
// TODO: Is this the line that caused wrong line numbers?
29+
// "target": "ES2020", // Modern browsers
30+
1631
"types": [
1732
"hasher",
1833
"q",
1934
"nanoid",
2035
"owasp-password-strength-test"
2136
],
2237
},
38+
"exclude": [
39+
"./**/*.d.ts"
40+
],
2341
"include": [
2442
"./**/*.ts"
2543
],

src/main/resources/tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
// This file is used by your code editor and the build system,
3-
// for TypeScript files except for those under ./assets/.
3+
// for TypeScript files except for those under ./assets/ and ./static/
44
// https://www.typescriptlang.org/tsconfig
55
"compilerOptions": {
66
"baseUrl": ".",
7+
"declaration": false,
78
"lib": [
89
"ES5"
910
],
@@ -17,13 +18,19 @@
1718
// "node_modules/@types",
1819
// "node_modules/@enonic-types"
1920
// ],
21+
"sourceMap": true, // Important to get correct line numbers?
22+
23+
// We set target in tsup.config.ts instead
24+
// "target": "es5",
25+
2026
"types": [
2127
"@enonic-types/global"
2228
// "global" // When typeRoots is set the prefix @enonic-types/ must be removed.
2329
]
2430
},
2531
"exclude": [
2632
"./assets/**/*",
33+
"./static/**/*",
2734
],
2835
"include": [
2936
"./**/*.ts"

tsconfig.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
{
1+
{ // https://www.typescriptlang.org/tsconfig
22
"compilerOptions": {
3+
"declaration": false,
34
"esModuleInterop": true, // Needed for the 'q' npm module
5+
"lib": [
6+
"es2015",
7+
"es2015.promise",
8+
"dom"
9+
],
410
"module": "commonjs",
5-
"target": "es5",
6-
"sourceMap": true,
11+
"sourceMap": true, // Important to get correct line numbers?
12+
13+
// We set target in tsup.config.ts instead
14+
// "target": "es5",
15+
716
"types": [
817
"hasher",
918
"q",
1019
"nanoid",
1120
"owasp-password-strength-test"
12-
],
13-
"lib": [
14-
"es2015",
15-
"es2015.promise",
16-
"dom"
1721
]
1822
},
1923
"exclude": [

tsup/static.ts

Lines changed: 83 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -11,82 +11,92 @@ import {
1111

1212

1313
export default function buildStaticConfig(): Options {
14-
const DIR_DST_STATIC = `${DIR_DST}/static`;
15-
// const GLOB_EXTENSIONS_STATIC = '{tsx,ts,jsx,js}';
16-
// const FILES_STATIC = globSync(`${DIR_SRC_STATIC}/**/*.${GLOB_EXTENSIONS_STATIC}`);
14+
const DIR_DST_STATIC = `${DIR_DST}/static`;
15+
// const GLOB_EXTENSIONS_STATIC = '{tsx,ts,jsx,js}';
16+
// const FILES_STATIC = globSync(`${DIR_SRC_STATIC}/**/*.${GLOB_EXTENSIONS_STATIC}`);
1717

18-
// const entry = {};
19-
// for (let i = 0; i < FILES_STATIC.length; i++) {
20-
// const element = FILES_STATIC[i];
21-
// entry[element
22-
// .replace(`${DIR_SRC_STATIC}/`, '') // Remove path
23-
// .replace(/\.[^.]+$/, '') // Remove extension
24-
// ] = element;
25-
// }
26-
return {
27-
bundle: true,
28-
dts: false,
29-
// entry,
30-
entry: {
31-
'app-users-bundle': 'src/main/resources/static/main.ts',
32-
'crypto-worker': 'src/main/resources/static/worker/RSAKeysWorker.ts',
33-
},
34-
// esbuildOptions(options, context) {
35-
// // options.banner = {
36-
// // js: `const jQuery = window.$;` // jQuery UI Tabbable requires this
37-
// // };
38-
// // options.external = [
39-
// // 'jquery'
40-
// // ]
41-
// },
42-
esbuildPlugins: [
43-
CopyWithHashPlugin({
44-
context: 'node_modules',
45-
manifest: `node_modules-manifest.json`,
46-
patterns: [
47-
'jquery/dist/*.*',
48-
'jquery-ui/dist/*.*',
49-
]
50-
}),
51-
TsupPluginManifest({
52-
generate: (entries) => {// Executed once per format
53-
const newEntries = {};
54-
Object.entries(entries).forEach(([k,v]) => {
55-
console.log(k,v);
56-
const ext = v.split('.').pop() as string;
57-
const parts = k.replace(`${DIR_SRC_STATIC}/`, '').split('.');
58-
parts.pop();
59-
parts.push(ext);
60-
newEntries[parts.join('.')] = v.replace(`${DIR_DST_STATIC}/`, '');
61-
});
62-
return newEntries;
63-
}
64-
}),
65-
],
66-
format: [
67-
'cjs'
68-
],
18+
// const entry = {};
19+
// for (let i = 0; i < FILES_STATIC.length; i++) {
20+
// const element = FILES_STATIC[i];
21+
// entry[element
22+
// .replace(`${DIR_SRC_STATIC}/`, '') // Remove path
23+
// .replace(/\.[^.]+$/, '') // Remove extension
24+
// ] = element;
25+
// }
26+
return {
27+
bundle: true,
28+
dts: false,
29+
// entry,
30+
entry: {
31+
'app-users-bundle': 'src/main/resources/static/main.ts',
32+
'crypto-worker': 'src/main/resources/static/worker/RSAKeysWorker.ts',
33+
},
34+
// esbuildOptions(options, context) {
35+
// // options.banner = {
36+
// // js: `const jQuery = window.$;` // jQuery UI Tabbable requires this
37+
// // };
38+
// // options.external = [
39+
// // 'jquery'
40+
// // ]
41+
// // options.sourcemap = 'external'; // Shows the line in the transpiled code, not the source
42+
// // options.sourcemap = 'both'; // // Shows the line in the transpiled code, not the source
43+
// },
44+
esbuildPlugins: [
45+
CopyWithHashPlugin({
46+
context: 'node_modules',
47+
manifest: `node_modules-manifest.json`,
48+
patterns: [
49+
'jquery/dist/*.*',
50+
'jquery-ui/dist/*.*',
51+
]
52+
}),
53+
TsupPluginManifest({
54+
generate: (entries) => {// Executed once per format
55+
const newEntries = {};
56+
Object.entries(entries).forEach(([k,v]) => {
57+
console.log(k,v);
58+
const ext = v.split('.').pop() as string;
59+
const parts = k.replace(`${DIR_SRC_STATIC}/`, '').split('.');
60+
parts.pop();
61+
parts.push(ext);
62+
newEntries[parts.join('.')] = v.replace(`${DIR_DST_STATIC}/`, '');
63+
});
64+
return newEntries;
65+
}
66+
}),
67+
],
68+
format: [
69+
'cjs'
70+
],
6971

70-
minify: false,
71-
// minify: process.env.NODE_ENV !== 'development',
72+
minify: false,
73+
// minify: process.env.NODE_ENV !== 'development',
74+
// minify: true, // Causes app-users-bundle-L6FTUX7O.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'insertChild')
7275

73-
noExternal: [ // Same as dependencies in package.json
74-
/@enonic\/lib-admin-ui.*/,
75-
'hasher',
76-
// 'jquery', // This will bundle jQuery into the bundle
77-
'nanoid',
78-
'owasp-password-strength-test',
79-
'q'
80-
],
81-
outDir: 'build/resources/main/static',
82-
platform: 'browser',
83-
silent: ['QUIET', 'WARN'].includes(process.env.LOG_LEVEL_FROM_GRADLE||''),
84-
splitting: false,
76+
noExternal: [ // Same as dependencies in package.json
77+
/@enonic\/lib-admin-ui.*/,
78+
'hasher',
79+
// 'jquery', // This will bundle jQuery into the bundle
80+
'nanoid',
81+
'owasp-password-strength-test',
82+
'q'
83+
],
84+
outDir: 'build/resources/main/static',
85+
platform: 'browser',
86+
silent: ['QUIET', 'WARN'].includes(process.env.LOG_LEVEL_FROM_GRADLE||''),
87+
splitting: false,
8588

86-
// sourcemap: false,
87-
sourcemap: process.env.NODE_ENV === 'development',
88-
// sourcemap: true,
89+
// Let tsconfig handle sourcemap?
90+
// sourcemap: false,
91+
// sourcemap: process.env.NODE_ENV === 'development'
92+
// ? 'inline' // Shows the line in the transpiled code, not the source
93+
// ? true // Shows the source typescript, but currently the wrong line number :(
94+
// : false,
95+
sourcemap: true,
8996

90-
tsconfig: 'src/main/resources/static/tsconfig.json',
91-
};
97+
// TODO: Is this the line that fixed wrong line numbers?
98+
target: 'es2020',
99+
100+
tsconfig: 'src/main/resources/static/tsconfig.json',
101+
};
92102
}

0 commit comments

Comments
 (0)