-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sourcemap): sourcemap 파일 생성 (#15)
* chore(package): @babel/generator 추가 * feat(sourcemap): sourcemap 생성 함수 * feat(path): add relative function * feat(parser): sourcemap 생성 연결 * chore(package): reinstall package * chore(package): delete package-lock.json * chore(package): add package-lock.json
- Loading branch information
Showing
6 changed files
with
73 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { CodeGenerator } from '@babel/generator'; | ||
import { createOutputFile } from '../output/index.js'; | ||
import PathUtil from '../util/path.js'; | ||
|
||
/** | ||
* generate sourcemap | ||
* @param {object} params | ||
* @param {object} params.ast | ||
* @param {string} params.fileContent | ||
* @param {string} params.filePath | ||
* @param {string} params.entryPath | ||
* @param {string} params.outputPath | ||
* | ||
* @returns {object} | ||
*/ | ||
export const createSourceMap = ({ | ||
ast, | ||
fileContent, | ||
filePath, | ||
entryPath, | ||
outputPath | ||
}) => { | ||
const sourceFileName = PathUtil.relative(outputPath, filePath); | ||
|
||
const generator = new CodeGenerator(ast, { sourceMaps: true, sourceFileName, sourceRoot: entryPath }, fileContent); | ||
const { map } = generator.generate(ast, {}, fileContent); | ||
|
||
return map; | ||
} | ||
|
||
/** | ||
* sourcemap 파일 작성 | ||
* @param {object} params | ||
* @param {object[]} params.modules | ||
* @param {string} params.outputPath | ||
*/ | ||
export const createSourceMapFile = ({ modules, outputPath }) => { | ||
modules.map(module => { | ||
const { sourceMapContent, filePath } = module; | ||
|
||
const parsedPaths = filePath.split('/'); | ||
const filename = parsedPaths[parsedPaths.length - 1]; | ||
|
||
createOutputFile({ path: outputPath, filename: `${filename}.map` }, JSON.stringify(sourceMapContent)); | ||
}); | ||
} |
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