Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
dcd784ee
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,发现更多精彩内容 >>
提交
dcd784ee
编写于
5月 04, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adopt new loader, fixes #25229
上级
3782c32c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
105 addition
and
40 deletion
+105
-40
src/vs/loader.js
src/vs/loader.js
+105
-40
未找到文件。
src/vs/loader.js
浏览文件 @
dcd784ee
...
...
@@ -583,24 +583,86 @@ var AMDLoader;
}());
var
NodeScriptLoader
=
(
function
()
{
function
NodeScriptLoader
()
{
this
.
_initialized
=
false
;
this
.
_didInitialize
=
false
;
this
.
_didPatchNodeRequire
=
false
;
// js-flags have an impact on cached data
this
.
_jsflags
=
''
;
for
(
var
_i
=
0
,
_a
=
process
.
argv
;
_i
<
_a
.
length
;
_i
++
)
{
var
arg
=
_a
[
_i
];
if
(
arg
.
indexOf
(
'
--js-flags=
'
)
===
0
)
{
this
.
_jsflags
=
arg
;
break
;
}
}
}
NodeScriptLoader
.
prototype
.
_init
=
function
(
nodeRequire
)
{
if
(
this
.
_
initialized
)
{
if
(
this
.
_
didInitialize
)
{
return
;
}
this
.
_
initialized
=
true
;
this
.
_
didInitialize
=
true
;
this
.
_fs
=
nodeRequire
(
'
fs
'
);
this
.
_vm
=
nodeRequire
(
'
vm
'
);
this
.
_path
=
nodeRequire
(
'
path
'
);
this
.
_crypto
=
nodeRequire
(
'
crypto
'
);
};
// patch require-function of nodejs such that we can manually create a script
// from cached data. this is done by overriding the `Module._compile` function
NodeScriptLoader
.
prototype
.
_initNodeRequire
=
function
(
nodeRequire
,
moduleManager
)
{
var
nodeCachedDataDir
=
moduleManager
.
getConfig
().
getOptionsLiteral
().
nodeCachedDataDir
;
if
(
!
nodeCachedDataDir
||
this
.
_didPatchNodeRequire
)
{
return
;
}
this
.
_didPatchNodeRequire
=
true
;
var
that
=
this
;
var
Module
=
nodeRequire
(
'
module
'
);
function
makeRequireFunction
(
mod
)
{
var
Module
=
mod
.
constructor
;
var
require
=
function
require
(
path
)
{
try
{
return
mod
.
require
(
path
);
}
finally
{
// nothing
}
};
require
.
resolve
=
function
resolve
(
request
)
{
return
Module
.
_resolveFilename
(
request
,
mod
);
};
require
.
main
=
process
.
mainModule
;
require
.
extensions
=
Module
.
_extensions
;
require
.
cache
=
Module
.
_cache
;
return
require
;
}
Module
.
prototype
.
_compile
=
function
(
content
,
filename
)
{
// remove shebang
content
=
content
.
replace
(
/^#!.*/
,
''
);
// create wrapper function
var
wrapper
=
Module
.
wrap
(
content
);
var
cachedDataPath
=
that
.
_getCachedDataPath
(
nodeCachedDataDir
,
filename
);
var
options
=
{
filename
:
filename
};
try
{
options
.
cachedData
=
that
.
_fs
.
readFileSync
(
cachedDataPath
);
}
catch
(
e
)
{
options
.
produceCachedData
=
true
;
}
var
script
=
new
that
.
_vm
.
Script
(
wrapper
,
options
);
var
compileWrapper
=
script
.
runInThisContext
(
options
);
var
dirname
=
that
.
_path
.
dirname
(
filename
);
var
require
=
makeRequireFunction
(
this
);
var
args
=
[
this
.
exports
,
require
,
this
,
filename
,
dirname
,
process
,
AMDLoader
.
global
,
Buffer
];
var
result
=
compileWrapper
.
apply
(
this
.
exports
,
args
);
that
.
_processCachedData
(
moduleManager
,
script
,
cachedDataPath
);
return
result
;
};
};
NodeScriptLoader
.
prototype
.
load
=
function
(
moduleManager
,
scriptSrc
,
callback
,
errorback
)
{
var
_this
=
this
;
var
opts
=
moduleManager
.
getConfig
().
getOptionsLiteral
();
var
nodeRequire
=
(
opts
.
nodeRequire
||
AMDLoader
.
global
.
nodeRequire
);
var
nodeInstrumenter
=
(
opts
.
nodeInstrumenter
||
function
(
c
)
{
return
c
;
});
this
.
_init
(
nodeRequire
);
this
.
_initNodeRequire
(
nodeRequire
,
moduleManager
);
var
recorder
=
moduleManager
.
getRecorder
();
if
(
/^node
\|
/
.
test
(
scriptSrc
))
{
var
pieces
=
scriptSrc
.
split
(
'
|
'
);
...
...
@@ -646,44 +708,16 @@ var AMDLoader;
}
else
{
var
cachedDataPath_1
=
_this
.
_getCachedDataPath
(
opts
.
nodeCachedDataDir
,
scriptSrc
);
_this
.
_fs
.
readFile
(
cachedDataPath_1
,
function
(
err
,
d
ata
)
{
_this
.
_fs
.
readFile
(
cachedDataPath_1
,
function
(
err
,
cachedD
ata
)
{
// create script options
var
scriptO
ptions
=
{
var
o
ptions
=
{
filename
:
vmScriptSrc
,
produceCachedData
:
typeof
d
ata
===
'
undefined
'
,
cachedData
:
d
ata
produceCachedData
:
typeof
cachedD
ata
===
'
undefined
'
,
cachedData
:
cachedD
ata
};
var
script
=
_this
.
_loadAndEvalScript
(
scriptSrc
,
vmScriptSrc
,
contents
,
scriptO
ptions
,
recorder
);
var
script
=
_this
.
_loadAndEvalScript
(
scriptSrc
,
vmScriptSrc
,
contents
,
o
ptions
,
recorder
);
callback
();
// cached code after math
if
(
script
.
cachedDataRejected
)
{
// data rejected => delete cache file
opts
.
onNodeCachedDataError
({
errorCode
:
'
cachedDataRejected
'
,
path
:
cachedDataPath_1
});
NodeScriptLoader
.
_runSoon
(
function
()
{
return
_this
.
_fs
.
unlink
(
cachedDataPath_1
,
function
(
err
)
{
if
(
err
)
{
moduleManager
.
getConfig
().
getOptionsLiteral
().
onNodeCachedDataError
({
errorCode
:
'
unlink
'
,
path
:
cachedDataPath_1
,
detail
:
err
});
}
});
},
opts
.
nodeCachedDataWriteDelay
);
}
else
if
(
script
.
cachedDataProduced
)
{
// data produced => write cache file
NodeScriptLoader
.
_runSoon
(
function
()
{
return
_this
.
_fs
.
writeFile
(
cachedDataPath_1
,
script
.
cachedData
,
function
(
err
)
{
if
(
err
)
{
moduleManager
.
getConfig
().
getOptionsLiteral
().
onNodeCachedDataError
({
errorCode
:
'
writeFile
'
,
path
:
cachedDataPath_1
,
detail
:
err
});
}
});
},
opts
.
nodeCachedDataWriteDelay
);
}
_this
.
_processCachedData
(
moduleManager
,
script
,
cachedDataPath_1
);
});
}
});
...
...
@@ -699,10 +733,41 @@ var AMDLoader;
recorder
.
record
(
AMDLoader
.
LoaderEventType
.
NodeEndEvaluatingScript
,
scriptSrc
);
return
script
;
};
NodeScriptLoader
.
prototype
.
_getCachedDataPath
=
function
(
base
D
ir
,
filename
)
{
var
hash
=
this
.
_crypto
.
createHash
(
'
md5
'
).
update
(
filename
,
'
utf8
'
).
digest
(
'
hex
'
);
NodeScriptLoader
.
prototype
.
_getCachedDataPath
=
function
(
base
d
ir
,
filename
)
{
var
hash
=
this
.
_crypto
.
createHash
(
'
md5
'
).
update
(
filename
,
'
utf8
'
).
update
(
this
.
_jsflags
,
'
utf8
'
).
digest
(
'
hex
'
);
var
basename
=
this
.
_path
.
basename
(
filename
).
replace
(
/
\.
js$/
,
''
);
return
this
.
_path
.
join
(
baseDir
,
hash
+
"
-
"
+
basename
+
"
.code
"
);
return
this
.
_path
.
join
(
basedir
,
basename
+
"
-
"
+
hash
+
"
.code
"
);
};
NodeScriptLoader
.
prototype
.
_processCachedData
=
function
(
moduleManager
,
script
,
cachedDataPath
)
{
var
_this
=
this
;
if
(
script
.
cachedDataRejected
)
{
// data rejected => delete cache file
moduleManager
.
getConfig
().
getOptionsLiteral
().
onNodeCachedDataError
({
errorCode
:
'
cachedDataRejected
'
,
path
:
cachedDataPath
});
NodeScriptLoader
.
_runSoon
(
function
()
{
return
_this
.
_fs
.
unlink
(
cachedDataPath
,
function
(
err
)
{
if
(
err
)
{
moduleManager
.
getConfig
().
getOptionsLiteral
().
onNodeCachedDataError
({
errorCode
:
'
unlink
'
,
path
:
cachedDataPath
,
detail
:
err
});
}
});
},
moduleManager
.
getConfig
().
getOptionsLiteral
().
nodeCachedDataWriteDelay
);
}
else
if
(
script
.
cachedDataProduced
)
{
// data produced => write cache file
NodeScriptLoader
.
_runSoon
(
function
()
{
return
_this
.
_fs
.
writeFile
(
cachedDataPath
,
script
.
cachedData
,
function
(
err
)
{
if
(
err
)
{
moduleManager
.
getConfig
().
getOptionsLiteral
().
onNodeCachedDataError
({
errorCode
:
'
writeFile
'
,
path
:
cachedDataPath
,
detail
:
err
});
}
});
},
moduleManager
.
getConfig
().
getOptionsLiteral
().
nodeCachedDataWriteDelay
);
}
};
NodeScriptLoader
.
_runSoon
=
function
(
callback
,
minTimeout
)
{
var
timeout
=
minTimeout
+
Math
.
ceil
(
Math
.
random
()
*
minTimeout
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录