-
Notifications
You must be signed in to change notification settings - Fork 448
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
Showing
14 changed files
with
242 additions
and
49 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 |
---|---|---|
|
@@ -14,4 +14,5 @@ node_js: | |
- "6" | ||
|
||
script: | ||
- npm run clean -- --when-ci-commit-message | ||
- npm run test -- --coverage |
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 @@ | ||
../../src/__helpers__/source-maps.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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
#!/usr/bin/env node | ||
|
||
const { removeSync } = require('fs-extra'); | ||
const Paths = require('./paths'); | ||
const { join } = require('path'); | ||
const { removeSync } = require('fs-extra') | ||
const Paths = require('./paths') | ||
const { join } = require('path') | ||
|
||
removeSync(Paths.distDir); | ||
removeSync(join(Paths.testsRootDir, '*', 'coverage')); | ||
removeSync(join(Paths.testsRootDir, '*', 'debug.txt')); | ||
removeSync(join(Paths.testsRootDir, '*', 'node_modules')); | ||
removeSync(join(Paths.e2eSourceDir, '*', 'node_modules')); | ||
removeSync(join(Paths.e2eTemplatesDir, '*', 'node_modules')); | ||
removeSync(Paths.e2eWorkDir); | ||
removeSync(Paths.e2eWotkDirLink); | ||
if (process.argv.indexOf('--when-ci-commit-message') !== -1) { | ||
let msg = | ||
process.env.TRAVIS_COMMIT_MESSAGE || | ||
process.env.APPVEYOR_REPO_COMMIT_MESSAGE | ||
if (!msg) | ||
throw new Error(`Unable to guess the commit message from CI env variables`) | ||
if (process.env.APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED) { | ||
msg = `${msg}\n${process.env.APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED}` | ||
} | ||
if (!/\[ci npm-clean\]/.test(msg)) return | ||
} | ||
|
||
removeSync(Paths.distDir) | ||
removeSync(join(Paths.testsRootDir, '*', 'coverage')) | ||
removeSync(join(Paths.testsRootDir, '*', 'debug.txt')) | ||
removeSync(join(Paths.testsRootDir, '*', 'node_modules')) | ||
removeSync(join(Paths.e2eSourceDir, '*', 'node_modules')) | ||
removeSync(join(Paths.e2eTemplatesDir, '*', 'node_modules')) | ||
removeSync(Paths.e2eWorkDir) | ||
removeSync(Paths.e2eWotkDirLink) |
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 @@ | ||
import { resolve, relative } from 'path' | ||
|
||
export const ROOT = resolve(__dirname, '..', '..') | ||
|
||
export function relativeToRoot(path: string) { | ||
return relative(ROOT, path) | ||
} |
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,49 @@ | ||
// WARNING: this file is shared between e2e and unit tests | ||
import { RawSourceMap } from 'source-map' | ||
import bufferFrom from 'buffer-from' | ||
import { relative, isAbsolute, resolve } from 'path' | ||
import stableStringify = require('fast-json-stable-stringify') | ||
import { realpathSync } from 'fs' | ||
|
||
// source-map module doesn't provide a sync method to extract the source-maps | ||
export function extractSourceMaps(source: string): RawSourceMap | undefined { | ||
const [, comment]: [any, string | undefined] = | ||
(source.match( | ||
/[\n^]\/\/#\s*sourceMappingURL=data:application\/json;(?:charset=utf-8;)?base64,(\S+)\s*$/, | ||
) as any) || [] | ||
if (!comment) return | ||
|
||
return base64ToSourceMaps(comment) | ||
} | ||
|
||
export function base64ToSourceMaps(base64: string): RawSourceMap { | ||
return JSON.parse(bufferFrom(base64, 'base64').toString('utf8')) | ||
} | ||
|
||
export function sourceMapsToBase64(sourceMaps: RawSourceMap): string { | ||
return bufferFrom(stableStringify(sourceMaps)).toString('base64') | ||
} | ||
|
||
export function relativiseSourceRoot( | ||
fromPath: string, | ||
source: string, | ||
prefix: string = '', | ||
): string { | ||
const from = realpathSync(fromPath) | ||
const remap = (path: string): string => | ||
(isAbsolute(path) | ||
? `${prefix}${relative(from, realpathSync(path))}` | ||
: path | ||
).replace(/\\/g, '/') | ||
|
||
return source.replace( | ||
/([\n^]\/\/#\s*sourceMappingURL=data:application\/json;(?:charset=utf-8;)?base64,)(\S+)(\s*)$/, | ||
(_, before, base64, after) => { | ||
const map = base64ToSourceMaps(base64) | ||
if (map.sourceRoot) map.sourceRoot = remap(map.sourceRoot) | ||
if (map.sources) map.sources = map.sources.map(remap) | ||
if (map.file) map.file = remap(map.file) | ||
return `${before}${sourceMapsToBase64(map)}${after}` | ||
}, | ||
) | ||
} |
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
Oops, something went wrong.