fix: module download error at windows remove okhttp lib

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-09-24 10:10:17 +08:00
parent 996a63ba2d
commit 388e1e9135
2 changed files with 6 additions and 23 deletions

19
pom.xml
View File

@ -33,10 +33,6 @@
<artifactSet>
<includes>
<include>org.kamranzafar:jtar</include>
<include>com.squareup.okhttp3:okhttp</include>
<include>com.squareup.okio:okio</include>
<include>org.jetbrains.kotlin:kotlin-stdlib</include>
<include>org.jetbrains.kotlin:kotlin-stdlib-common</include>
</includes>
</artifactSet>
</configuration>
@ -167,21 +163,6 @@
<artifactId>jtar</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.3.50</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-common</artifactId>
<version>1.3.50</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>

View File

@ -230,8 +230,9 @@
// handle name es6-map/implement => es6-map @ms/common/dist/reflect => @ms/common
var name_arr = name.split('/');
var module_name = name.startsWith('@') ? name_arr[0] + '/' + name_arr[1] : name_arr[0];
var tempFile = Files.createTempDirectory('MiaoScript').resolve(module_name + '.tgz');
Files.copy(new URL('https://repo.yumc.pw/repository/npm/' + module_name).openStream(), tempFile, StandardCopyOption.REPLACE_EXISTING)
// at windows need replace file name java.lang.IllegalArgumentException: Invalid prefix or suffix
var tempFile = Files.createTempFile(module_name.replace('/', '_'), 'json');
Files.copy(new URL('https://repo.yumc.pw/repository/npm/' + module_name).openStream(), tempFile, StandardCopyOption.REPLACE_EXISTING);
var info = JSON.parse(new java.lang.String(Files.readAllBytes(tempFile), 'UTF-8'));
var url = info.versions[info['dist-tags']['latest']].dist.tarball;
console.log('node_module ' + module_name + ' not found at local but exist at internet ' + url + ' downloading...')
@ -258,9 +259,10 @@
optional = __assign({ cache: true }, optional);
if (file === undefined) {
try {
if (optional.recursive || notFoundModules[name]) {
// excloud local dir, prevent too many recursive call and cache not found module
if (name.startsWith('.') || name.startsWith('/') || optional.recursive || notFoundModules[name]) {
console.log(name, path, optional, notFoundModules[name])
throw new Error("Can't found module " + name + ' in network!')
throw new Error("Can't found module " + name + ' at local or network!')
}
optional.recursive = true;
return _require(download(name), path, optional);