-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05ea89d
commit b477374
Showing
6 changed files
with
104 additions
and
17 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"dependencies": { | ||
"@dd/core": "workspace:*", | ||
"chalk": "2.3.1", | ||
"glob": "7.1.6", | ||
"unplugin": "1.10.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
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,50 @@ | ||
import chalk from 'chalk'; | ||
import glob from 'glob'; | ||
import path from 'path'; | ||
|
||
import type { RumSourcemapsOptionsWithDefaults, Sourcemap } from '../types'; | ||
|
||
type PartialSourcemap = Pick<Sourcemap, 'minifiedFilePath' | 'minifiedUrl' | 'relativePath'>; | ||
|
||
const getGlobPattern = (basePath: string) => { | ||
// Normalizing the basePath to resolve .. and . | ||
// Always using the posix version to avoid \ on Windows. | ||
const newPath = path.posix.normalize(basePath); | ||
// TODO Test for .mjs files | ||
return path.join(newPath, '**/*.@(js|mjs).map'); | ||
}; | ||
|
||
const decomposePath = ( | ||
options: RumSourcemapsOptionsWithDefaults, | ||
sourcemapFilePath: string, | ||
): PartialSourcemap => { | ||
if (path.extname(sourcemapFilePath) !== '.map') { | ||
throw new Error(`The file ${chalk.green.bold(sourcemapFilePath)} is not a sourcemap.`); | ||
} | ||
|
||
const minifiedFilePath = sourcemapFilePath.replace(/\.map$/, ''); | ||
const relativePath = minifiedFilePath.replace(options.basePath, ''); | ||
const minifiedUrl = options.minifiedPathPrefix | ||
? path.join(options.minifiedPathPrefix, relativePath) | ||
: relativePath; | ||
|
||
return { | ||
minifiedFilePath, | ||
minifiedUrl, | ||
relativePath, | ||
}; | ||
}; | ||
|
||
export const getSourcemapsFiles = (options: RumSourcemapsOptionsWithDefaults): Sourcemap[] => { | ||
const globPattern = getGlobPattern(options.basePath); | ||
const sourcemapFilesList = glob.sync(globPattern); | ||
const sourcemapFiles = sourcemapFilesList.map((sourcemapFilePath) => { | ||
return { | ||
...decomposePath(options, sourcemapFilePath), | ||
sourcemapFilePath, | ||
minifiedPathPrefix: options.minifiedPathPrefix, | ||
}; | ||
}); | ||
|
||
return sourcemapFiles; | ||
}; |
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,23 @@ | ||
import type { Logger } from '@dd/core/log'; | ||
|
||
import type { RumOptionsWithDefaults } from '../types'; | ||
|
||
import { getSourcemapsFiles } from './files'; | ||
import { getPayloads } from './sender'; | ||
|
||
export const uploadSourcemaps = async (options: RumOptionsWithDefaults, log: Logger) => { | ||
if (!options.sourcemaps) { | ||
log(`Sourcemaps are not configured.`, 'warn'); | ||
return; | ||
} | ||
|
||
log(`Uploading sourcemaps.`); | ||
|
||
// Gather the sourcemaps files. | ||
const sourcemaps = getSourcemapsFiles(options.sourcemaps); | ||
|
||
// Build payloads (with git info from context plugin). | ||
const payloads = getPayloads(sourcemaps, options); | ||
|
||
// Upload the sourcemaps. | ||
}; |
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,3 @@ | ||
import type { RumOptionsWithDefaults, Sourcemap } from '../types'; | ||
|
||
export const getPayloads = (sourcemaps: Sourcemap[], options: RumOptionsWithDefaults) => {}; |
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