Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9198116d
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9198116d
编写于
7月 28, 2020
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `IOptimizeTaskOpts.fileContentMapper`
上级
15e798e0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
17 deletion
+24
-17
build/lib/optimize.js
build/lib/optimize.js
+9
-6
build/lib/optimize.ts
build/lib/optimize.ts
+15
-11
未找到文件。
build/lib/optimize.js
浏览文件 @
9198116d
...
@@ -70,7 +70,7 @@ function loader(src, bundledFileHeader, bundleLoader) {
...
@@ -70,7 +70,7 @@ function loader(src, bundledFileHeader, bundleLoader) {
}))
}))
.
pipe
(
concat
(
'
vs/loader.js
'
)));
.
pipe
(
concat
(
'
vs/loader.js
'
)));
}
}
function
toConcatStream
(
src
,
bundledFileHeader
,
sources
,
dest
)
{
function
toConcatStream
(
src
,
bundledFileHeader
,
sources
,
dest
,
fileContentMapper
)
{
const
useSourcemaps
=
/
\.
js$/
.
test
(
dest
)
&&
!
/
\.
nls
\.
js$/
.
test
(
dest
);
const
useSourcemaps
=
/
\.
js$/
.
test
(
dest
)
&&
!
/
\.
nls
\.
js$/
.
test
(
dest
);
// If a bundle ends up including in any of the sources our copyright, then
// If a bundle ends up including in any of the sources our copyright, then
// insert a fake source at the beginning of each bundle with our copyright
// insert a fake source at the beginning of each bundle with our copyright
...
@@ -91,10 +91,12 @@ function toConcatStream(src, bundledFileHeader, sources, dest) {
...
@@ -91,10 +91,12 @@ function toConcatStream(src, bundledFileHeader, sources, dest) {
const
treatedSources
=
sources
.
map
(
function
(
source
)
{
const
treatedSources
=
sources
.
map
(
function
(
source
)
{
const
root
=
source
.
path
?
REPO_ROOT_PATH
.
replace
(
/
\\
/g
,
'
/
'
)
:
''
;
const
root
=
source
.
path
?
REPO_ROOT_PATH
.
replace
(
/
\\
/g
,
'
/
'
)
:
''
;
const
base
=
source
.
path
?
root
+
`/
${
src
}
`
:
''
;
const
base
=
source
.
path
?
root
+
`/
${
src
}
`
:
''
;
const
path
=
source
.
path
?
root
+
'
/
'
+
source
.
path
.
replace
(
/
\\
/g
,
'
/
'
)
:
'
fake
'
;
const
contents
=
source
.
path
?
fileContentMapper
(
source
.
contents
,
path
)
:
source
.
contents
;
return
new
VinylFile
({
return
new
VinylFile
({
path
:
source
.
path
?
root
+
'
/
'
+
source
.
path
.
replace
(
/
\\
/g
,
'
/
'
)
:
'
fake
'
,
path
:
path
,
base
:
base
,
base
:
base
,
contents
:
Buffer
.
from
(
source
.
contents
)
contents
:
Buffer
.
from
(
contents
)
});
});
});
});
return
es
.
readArray
(
treatedSources
)
return
es
.
readArray
(
treatedSources
)
...
@@ -102,9 +104,9 @@ function toConcatStream(src, bundledFileHeader, sources, dest) {
...
@@ -102,9 +104,9 @@ function toConcatStream(src, bundledFileHeader, sources, dest) {
.
pipe
(
concat
(
dest
))
.
pipe
(
concat
(
dest
))
.
pipe
(
stats_1
.
createStatsStream
(
dest
));
.
pipe
(
stats_1
.
createStatsStream
(
dest
));
}
}
function
toBundleStream
(
src
,
bundledFileHeader
,
bundles
)
{
function
toBundleStream
(
src
,
bundledFileHeader
,
bundles
,
fileContentMapper
)
{
return
es
.
merge
(
bundles
.
map
(
function
(
bundle
)
{
return
es
.
merge
(
bundles
.
map
(
function
(
bundle
)
{
return
toConcatStream
(
src
,
bundledFileHeader
,
bundle
.
sources
,
bundle
.
dest
);
return
toConcatStream
(
src
,
bundledFileHeader
,
bundle
.
sources
,
bundle
.
dest
,
fileContentMapper
);
}));
}));
}
}
const
DEFAULT_FILE_HEADER
=
[
const
DEFAULT_FILE_HEADER
=
[
...
@@ -120,6 +122,7 @@ function optimizeTask(opts) {
...
@@ -120,6 +122,7 @@ function optimizeTask(opts) {
const
bundledFileHeader
=
opts
.
header
||
DEFAULT_FILE_HEADER
;
const
bundledFileHeader
=
opts
.
header
||
DEFAULT_FILE_HEADER
;
const
bundleLoader
=
(
typeof
opts
.
bundleLoader
===
'
undefined
'
?
true
:
opts
.
bundleLoader
);
const
bundleLoader
=
(
typeof
opts
.
bundleLoader
===
'
undefined
'
?
true
:
opts
.
bundleLoader
);
const
out
=
opts
.
out
;
const
out
=
opts
.
out
;
const
fileContentMapper
=
opts
.
fileContentMapper
||
((
contents
,
_path
)
=>
contents
);
return
function
()
{
return
function
()
{
const
bundlesStream
=
es
.
through
();
// this stream will contain the bundled files
const
bundlesStream
=
es
.
through
();
// this stream will contain the bundled files
const
resourcesStream
=
es
.
through
();
// this stream will contain the resources
const
resourcesStream
=
es
.
through
();
// this stream will contain the resources
...
@@ -128,7 +131,7 @@ function optimizeTask(opts) {
...
@@ -128,7 +131,7 @@ function optimizeTask(opts) {
if
(
err
||
!
result
)
{
if
(
err
||
!
result
)
{
return
bundlesStream
.
emit
(
'
error
'
,
JSON
.
stringify
(
err
));
return
bundlesStream
.
emit
(
'
error
'
,
JSON
.
stringify
(
err
));
}
}
toBundleStream
(
src
,
bundledFileHeader
,
result
.
files
).
pipe
(
bundlesStream
);
toBundleStream
(
src
,
bundledFileHeader
,
result
.
files
,
fileContentMapper
).
pipe
(
bundlesStream
);
// Remove css inlined resources
// Remove css inlined resources
const
filteredResources
=
resources
.
slice
();
const
filteredResources
=
resources
.
slice
();
result
.
cssInlinedResources
.
forEach
(
function
(
resource
)
{
result
.
cssInlinedResources
.
forEach
(
function
(
resource
)
{
...
...
build/lib/optimize.ts
浏览文件 @
9198116d
...
@@ -18,7 +18,6 @@ import * as fancyLog from 'fancy-log';
...
@@ -18,7 +18,6 @@ import * as fancyLog from 'fancy-log';
import
*
as
ansiColors
from
'
ansi-colors
'
;
import
*
as
ansiColors
from
'
ansi-colors
'
;
import
*
as
path
from
'
path
'
;
import
*
as
path
from
'
path
'
;
import
*
as
pump
from
'
pump
'
;
import
*
as
pump
from
'
pump
'
;
import
*
as
sm
from
'
source-map
'
;
import
*
as
terser
from
'
terser
'
;
import
*
as
terser
from
'
terser
'
;
import
*
as
VinylFile
from
'
vinyl
'
;
import
*
as
VinylFile
from
'
vinyl
'
;
import
*
as
bundle
from
'
./bundle
'
;
import
*
as
bundle
from
'
./bundle
'
;
...
@@ -48,10 +47,6 @@ export function loaderConfig() {
...
@@ -48,10 +47,6 @@ export function loaderConfig() {
const
IS_OUR_COPYRIGHT_REGEXP
=
/Copyright
\(
C
\)
Microsoft Corporation/i
;
const
IS_OUR_COPYRIGHT_REGEXP
=
/Copyright
\(
C
\)
Microsoft Corporation/i
;
declare
class
FileSourceMap
extends
VinylFile
{
public
sourceMap
:
sm
.
RawSourceMap
;
}
function
loader
(
src
:
string
,
bundledFileHeader
:
string
,
bundleLoader
:
boolean
):
NodeJS
.
ReadWriteStream
{
function
loader
(
src
:
string
,
bundledFileHeader
:
string
,
bundleLoader
:
boolean
):
NodeJS
.
ReadWriteStream
{
let
sources
=
[
let
sources
=
[
`
${
src
}
/vs/loader.js`
`
${
src
}
/vs/loader.js`
...
@@ -84,7 +79,7 @@ function loader(src: string, bundledFileHeader: string, bundleLoader: boolean):
...
@@ -84,7 +79,7 @@ function loader(src: string, bundledFileHeader: string, bundleLoader: boolean):
);
);
}
}
function
toConcatStream
(
src
:
string
,
bundledFileHeader
:
string
,
sources
:
bundle
.
IFile
[],
dest
:
string
):
NodeJS
.
ReadWriteStream
{
function
toConcatStream
(
src
:
string
,
bundledFileHeader
:
string
,
sources
:
bundle
.
IFile
[],
dest
:
string
,
fileContentMapper
:
(
contents
:
string
,
path
:
string
)
=>
string
):
NodeJS
.
ReadWriteStream
{
const
useSourcemaps
=
/
\.
js$/
.
test
(
dest
)
&&
!
/
\.
nls
\.
js$/
.
test
(
dest
);
const
useSourcemaps
=
/
\.
js$/
.
test
(
dest
)
&&
!
/
\.
nls
\.
js$/
.
test
(
dest
);
// If a bundle ends up including in any of the sources our copyright, then
// If a bundle ends up including in any of the sources our copyright, then
...
@@ -108,11 +103,13 @@ function toConcatStream(src: string, bundledFileHeader: string, sources: bundle.
...
@@ -108,11 +103,13 @@ function toConcatStream(src: string, bundledFileHeader: string, sources: bundle.
const
treatedSources
=
sources
.
map
(
function
(
source
)
{
const
treatedSources
=
sources
.
map
(
function
(
source
)
{
const
root
=
source
.
path
?
REPO_ROOT_PATH
.
replace
(
/
\\
/g
,
'
/
'
)
:
''
;
const
root
=
source
.
path
?
REPO_ROOT_PATH
.
replace
(
/
\\
/g
,
'
/
'
)
:
''
;
const
base
=
source
.
path
?
root
+
`/
${
src
}
`
:
''
;
const
base
=
source
.
path
?
root
+
`/
${
src
}
`
:
''
;
const
path
=
source
.
path
?
root
+
'
/
'
+
source
.
path
.
replace
(
/
\\
/g
,
'
/
'
)
:
'
fake
'
;
const
contents
=
source
.
path
?
fileContentMapper
(
source
.
contents
,
path
)
:
source
.
contents
;
return
new
VinylFile
({
return
new
VinylFile
({
path
:
source
.
path
?
root
+
'
/
'
+
source
.
path
.
replace
(
/
\\
/g
,
'
/
'
)
:
'
fake
'
,
path
:
path
,
base
:
base
,
base
:
base
,
contents
:
Buffer
.
from
(
source
.
contents
)
contents
:
Buffer
.
from
(
contents
)
});
});
});
});
...
@@ -122,9 +119,9 @@ function toConcatStream(src: string, bundledFileHeader: string, sources: bundle.
...
@@ -122,9 +119,9 @@ function toConcatStream(src: string, bundledFileHeader: string, sources: bundle.
.
pipe
(
createStatsStream
(
dest
));
.
pipe
(
createStatsStream
(
dest
));
}
}
function
toBundleStream
(
src
:
string
,
bundledFileHeader
:
string
,
bundles
:
bundle
.
IConcatFile
[]):
NodeJS
.
ReadWriteStream
{
function
toBundleStream
(
src
:
string
,
bundledFileHeader
:
string
,
bundles
:
bundle
.
IConcatFile
[]
,
fileContentMapper
:
(
contents
:
string
,
path
:
string
)
=>
string
):
NodeJS
.
ReadWriteStream
{
return
es
.
merge
(
bundles
.
map
(
function
(
bundle
)
{
return
es
.
merge
(
bundles
.
map
(
function
(
bundle
)
{
return
toConcatStream
(
src
,
bundledFileHeader
,
bundle
.
sources
,
bundle
.
dest
);
return
toConcatStream
(
src
,
bundledFileHeader
,
bundle
.
sources
,
bundle
.
dest
,
fileContentMapper
);
}));
}));
}
}
...
@@ -162,6 +159,12 @@ export interface IOptimizeTaskOpts {
...
@@ -162,6 +159,12 @@ export interface IOptimizeTaskOpts {
* (out folder name)
* (out folder name)
*/
*/
languages
?:
Language
[];
languages
?:
Language
[];
/**
* File contents interceptor
* @param contents The contens of the file
* @param path The absolute file path, always using `/`, even on Windows
*/
fileContentMapper
?:
(
contents
:
string
,
path
:
string
)
=>
string
;
}
}
const
DEFAULT_FILE_HEADER
=
[
const
DEFAULT_FILE_HEADER
=
[
...
@@ -178,6 +181,7 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
...
@@ -178,6 +181,7 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
const
bundledFileHeader
=
opts
.
header
||
DEFAULT_FILE_HEADER
;
const
bundledFileHeader
=
opts
.
header
||
DEFAULT_FILE_HEADER
;
const
bundleLoader
=
(
typeof
opts
.
bundleLoader
===
'
undefined
'
?
true
:
opts
.
bundleLoader
);
const
bundleLoader
=
(
typeof
opts
.
bundleLoader
===
'
undefined
'
?
true
:
opts
.
bundleLoader
);
const
out
=
opts
.
out
;
const
out
=
opts
.
out
;
const
fileContentMapper
=
opts
.
fileContentMapper
||
((
contents
:
string
,
_path
:
string
)
=>
contents
);
return
function
()
{
return
function
()
{
const
bundlesStream
=
es
.
through
();
// this stream will contain the bundled files
const
bundlesStream
=
es
.
through
();
// this stream will contain the bundled files
...
@@ -187,7 +191,7 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
...
@@ -187,7 +191,7 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
bundle
.
bundle
(
entryPoints
,
loaderConfig
,
function
(
err
,
result
)
{
bundle
.
bundle
(
entryPoints
,
loaderConfig
,
function
(
err
,
result
)
{
if
(
err
||
!
result
)
{
return
bundlesStream
.
emit
(
'
error
'
,
JSON
.
stringify
(
err
));
}
if
(
err
||
!
result
)
{
return
bundlesStream
.
emit
(
'
error
'
,
JSON
.
stringify
(
err
));
}
toBundleStream
(
src
,
bundledFileHeader
,
result
.
files
).
pipe
(
bundlesStream
);
toBundleStream
(
src
,
bundledFileHeader
,
result
.
files
,
fileContentMapper
).
pipe
(
bundlesStream
);
// Remove css inlined resources
// Remove css inlined resources
const
filteredResources
=
resources
.
slice
();
const
filteredResources
=
resources
.
slice
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录