-
Notifications
You must be signed in to change notification settings - Fork 27
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 #991 from ckeditor/fix-source-maps-in-umd-build
Fix (build-tools): Fixed source maps generation for the UMD build. Fixes ckeditor/ckeditor5#16984. Feature (build-tools): Introduced a new `loadSourcemaps` plugin for loading source maps of external dependencies.
- Loading branch information
Showing
11 changed files
with
151 additions
and
43 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
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
25 changes: 25 additions & 0 deletions
25
packages/ckeditor5-dev-build-tools/src/plugins/loadSourcemaps.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,25 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import fs from 'fs'; | ||
import type { Plugin } from 'rollup'; | ||
|
||
export function loadSourcemaps(): Plugin { | ||
return { | ||
name: 'cke5-load-sourcemaps', | ||
load( id: string ) { | ||
const sourceMapId = id + '.map'; | ||
|
||
if ( !fs.existsSync( sourceMapId ) ) { | ||
return; | ||
} | ||
|
||
return { | ||
code: fs.readFileSync( id, 'utf-8' ), | ||
map: fs.readFileSync( sourceMapId, 'utf-8' ) | ||
}; | ||
} | ||
}; | ||
} |
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
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
7 changes: 7 additions & 0 deletions
7
packages/ckeditor5-dev-build-tools/tests/plugins/loadSourcemaps/fixtures/input.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,7 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
// The `magic-string` package is used because it contains source maps. | ||
export { default as MagicString } from 'magic-string'; |
17 changes: 17 additions & 0 deletions
17
packages/ckeditor5-dev-build-tools/tests/plugins/loadSourcemaps/fixtures/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"lib": [ | ||
"ES2022", | ||
"DOM", | ||
"DOM.Iterable" | ||
], | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true | ||
}, | ||
"include": [ | ||
"**/*" | ||
] | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/ckeditor5-dev-build-tools/tests/plugins/loadSourcemaps/loadSourcemaps.test.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,46 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { join } from 'path'; | ||
import { test, expect } from 'vitest'; | ||
import { rollup, type RollupOutput, type OutputAsset } from 'rollup'; | ||
import { nodeResolve } from '@rollup/plugin-node-resolve'; | ||
import { swcPlugin } from '../../_utils/utils.js'; | ||
|
||
import { loadSourcemaps } from '../../../src/index.js'; | ||
import { getOptionalPlugin } from '../../../src/utils.js'; | ||
|
||
async function generateBundle( input: string, sourcemap: boolean = false ): Promise<RollupOutput[ 'output' ]> { | ||
const bundle = await rollup( { | ||
input: join( import.meta.dirname, input ), | ||
plugins: [ | ||
nodeResolve(), | ||
swcPlugin, | ||
getOptionalPlugin( sourcemap, loadSourcemaps() ) | ||
] | ||
} ); | ||
|
||
const { output } = await bundle.generate( { | ||
format: 'esm', | ||
file: 'input.js', | ||
assetFileNames: '[name][extname]', | ||
sourcemap | ||
} ); | ||
|
||
return output; | ||
} | ||
|
||
test( 'Emits source maps combined with source maps of dependencies', async () => { | ||
const output = await generateBundle( './fixtures/input.ts', true ); | ||
const sourceMap = output.find( asset => asset.fileName === 'input.js.map' ) as OutputAsset; | ||
|
||
/** | ||
* The resulting source map will only contain the `/magic-string/src/` string if the source map | ||
* of the `magic-string` dependency was loaded and combined with the source map of the input file. | ||
* Otherwise, the source map will contain the `/magic-string/dist/` string, which is the bundled | ||
* build of the `magic-string` dependency. | ||
*/ | ||
expect( sourceMap.source ).toContain( '/magic-string/src/' ); | ||
} ); |