Skip to content

Commit

Permalink
perf: lazy imports, get rid of tsAwaiter
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Oct 20, 2016
1 parent a0e7131 commit a33e004
Show file tree
Hide file tree
Showing 84 changed files with 704 additions and 590 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/electron-builder.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/ArtifactPublisherTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/compile.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/lint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/typescript-compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nsis-auto-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"dependencies": {
"bluebird": "^3.4.6",
"fs-extra-p": "^1.1.10",
"fs-extra-p": "^1.2.0",
"ini": "^1.3.4",
"semver": "^5.3.0",
"source-map-support": "^0.4.5",
Expand Down
3 changes: 0 additions & 3 deletions nsis-auto-updater/src/BintrayProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { BintrayClient } from "../../src/publish/bintray"
import { HttpError } from "../../src/publish/restApiRequest"
import { BintrayOptions } from "../../src/options/publishOptions"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("../../src/util/awaiter")

export class BintrayProvider implements Provider {
private client: BintrayClient

Expand Down
16 changes: 9 additions & 7 deletions nsis-auto-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { EventEmitter } from "events"
import { spawn } from "child_process"
import * as path from "path"
import { tmpdir } from "os"
import semver = require("semver")
import { gt as isVersionGreaterThan, valid as parseVersion } from "semver"
import { download } from "../../src/util/httpRequest"
import { Provider, UpdateCheckResult } from "./api"
import { BintrayProvider } from "./BintrayProvider"
import { Promise as BluebirdPromise } from "bluebird"
import BluebirdPromise from "bluebird"
import { BintrayOptions, PublishConfiguration, GithubOptions } from "../../src/options/publishOptions"
import { readJson } from "fs-extra-p"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("../../src/util/awaiter")
BluebirdPromise.config({
longStackTraces: true,
cancellation: true
})

export class NsisUpdater extends EventEmitter {
private setupPath: string | null
Expand Down Expand Up @@ -60,17 +62,17 @@ export class NsisUpdater extends EventEmitter {
const client = await this.clientPromise
const versionInfo = await client.getLatestVersion()

const latestVersion = semver.valid(versionInfo.version)
const latestVersion = parseVersion(versionInfo.version)
if (latestVersion == null) {
throw new Error(`Latest version (from update server) is not valid semver version: "${latestVersion}`)
}

const currentVersion = semver.valid(this.app.getVersion())
const currentVersion = parseVersion(this.app.getVersion())
if (currentVersion == null) {
throw new Error(`App version is not valid semver version: "${currentVersion}`)
}

if (semver.gte(currentVersion, latestVersion)) {
if (isVersionGreaterThan(currentVersion, latestVersion)) {
this.updateAvailable = false
this.emit("update-not-available")
return {
Expand Down
15 changes: 5 additions & 10 deletions nsis-auto-updater/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"module": "es2015",
"target": "es2017",
"noImplicitAny": true,
"outDir": "out",
"newLine": "LF",
"noResolve": true,
"noEmitOnError": true,
"inlineSources": true,
"sourceMap": true,
Expand All @@ -20,20 +19,16 @@
"": "../test/typings/electron-auto-updater.d.ts"
},
"files": [
"../typings/semver.d.ts",
"../node_modules/@types/node/index.d.ts",
"../node_modules/@types/semver/index.d.ts",
"../node_modules/fs-extra-p/index.d.ts",
"../node_modules/fs-extra-p/bluebird.d.ts",
"../node_modules/@develar/types/bluebird.d.ts",
"../src/util/httpRequest.ts",
"../src/publish/restApiRequest.ts",
"../src/publish/restApiRequest.ts",
"../src/publish/bintray.ts",
"../src/options/publishOptions.ts",
"../src/util/awaiter.ts"
"../src/publish/bintray.ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
]
}
35 changes: 20 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
"node-gyp-rebuild": "./out/node-gyp-rebuild.js"
},
"scripts": {
"compile": "npm run compile-production && npm run compile-updater && npm run compile-test",
"compile-production": "ts-babel",
"compile-test": "ts-babel test",
"compile-updater": "ts-babel nsis-auto-updater",
"compile": "ts-babel . nsis-auto-updater test",
"lint": "tslint 'src/**/*.ts' 'test/src/**/*.ts' 'nsis-auto-updater/src/**/*.ts'",
"pretest": "npm run compile && npm run lint && npm run pack-updater",
"test": "node ./test/out/helpers/runTests.js",
Expand Down Expand Up @@ -59,7 +56,7 @@
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"7zip-bin": "^2.0.3",
"7zip-bin": "^2.0.4",
"ansi-escapes": "^1.4.0",
"archiver": "^1.1.0",
"archiver-utils": "^1.3.0",
Expand All @@ -71,14 +68,15 @@
"cuint": "^0.2.2",
"debug": "^2.2.0",
"electron-download": "2.1.2",
"electron-osx-sign-tf": "^1.0.0",
"fs-extra-p": "^1.1.10",
"electron-osx-sign-tf": "^1.0.1",
"fs-extra-p": "^1.2.0",
"hosted-git-info": "^2.1.5",
"ini": "^1.3.4",
"isbinaryfile": "^3.0.1",
"lodash.template": "^4.4.0",
"mime": "^1.3.4",
"minimatch": "^3.0.3",
"nodent-runtime": "^3.0.1",
"normalize-package-data": "^2.3.5",
"parse-color": "^1.0.0",
"plist": "^2.0.1",
Expand All @@ -95,14 +93,13 @@
"yargs": "^6.0.0"
},
"devDependencies": {
"@develar/babel-plugin-transform-inline-imports-commonjs": "^1.0.0",
"@develar/semantic-release": "^6.3.6",
"@types/debug": "0.0.29",
"@types/mime": "0.0.29",
"@types/progress": "^1.1.28",
"@types/semver": "^5.3.30",
"@develar/types": "^1.0.1",
"@types/source-map-support": "^0.2.28",
"ava-tf": "^0.16.2",
"ava-tf": "^0.16.4",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-async-to-module-method": "^6.16.0",
"babel-plugin-transform-es2015-destructuring": "^6.16.0",
"babel-plugin-transform-es2015-parameters": "^6.17.0",
"babel-plugin-transform-es2015-spread": "^6.8.0",
Expand All @@ -111,18 +108,26 @@
"husky": "^0.11.9",
"json8": "^0.9.2",
"path-sort": "^0.1.0",
"ts-babel": "^1.0.13",
"ts-babel": "^1.1.2",
"tslint": "^3.15.1",
"typescript": "^2.0.3",
"typescript": "^2.1.0-dev.20161019",
"validate-commit-msg": "^2.8.2",
"whitespace": "^2.1.0"
},
"babel": {
"plugins": [
[
"transform-async-to-module-method",
{
"module": "bluebird",
"method": "coroutine"
}
],
"transform-es2015-parameters",
"transform-es2015-spread",
"transform-es2015-destructuring",
"array-includes"
"array-includes",
"@develar/babel-plugin-transform-inline-imports-commonjs"
]
},
"ava": {
Expand Down
5 changes: 1 addition & 4 deletions src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { warn } from "./util/log"
import { smarten } from "./platformPackager"
import { isEmptyOrSpaces } from "./util/util"
import { getRepositoryInfo } from "./repositoryInfo"
import sanitizeFileName = require("sanitize-filename")

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./util/awaiter")
import sanitizeFileName from "sanitize-filename"

export class AppInfo {
readonly description = smarten(this.metadata.description!)
Expand Down
89 changes: 42 additions & 47 deletions src/asarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
lstat, readdir, readFile, Stats, createWriteStream, ensureDir, createReadStream, readJson,
writeFile, realpath
} from "fs-extra-p"
import { Promise as BluebirdPromise } from "bluebird"
import BluebirdPromise from "bluebird"
import * as path from "path"
import { log } from "./util/log"
import { Minimatch } from "minimatch"
Expand All @@ -16,62 +16,57 @@ const pickle = require ("chromium-pickle-js")
const Filesystem = require("asar-electron-builder/lib/filesystem")
const UINT64 = require("cuint").UINT64

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./util/awaiter")

const MAX_FILE_REQUESTS = 32
const concurrency = {concurrency: MAX_FILE_REQUESTS}
const NODE_MODULES_PATTERN = path.sep + "node_modules" + path.sep

export function walk(dirPath: string, consumer?: (file: string, stat: Stats) => void, filter?: Filter, addRootToResult?: boolean): BluebirdPromise<Array<string>> {
return readdir(dirPath)
.then(names => BluebirdPromise.map(names, name => {
const filePath = dirPath + path.sep + name
return lstat(filePath)
.then((stat): any => {
if (filter != null && !filter(filePath, stat)) {
return null
}

if (consumer != null) {
consumer(filePath, stat)
}
if (stat.isDirectory()) {
return walk(filePath, consumer, filter, true)
}
return filePath
})
}, concurrency))
.then(list => {
list.sort((a, b) => {
// files before directories
if (Array.isArray(a) && Array.isArray(b)) {
return 0
export async function walk(dirPath: string, consumer?: (file: string, stat: Stats) => void, filter?: Filter, addRootToResult?: boolean): Promise<Array<string>> {
const list = await BluebirdPromise.map(await readdir(dirPath), name => {
const filePath = dirPath + path.sep + name
return lstat(filePath)
.then((stat): any => {
if (filter != null && !filter(filePath, stat)) {
return null
}
else if (a == null || Array.isArray(a)) {
return 1
}
else if (b == null || Array.isArray(b)) {
return -1

if (consumer != null) {
consumer(filePath, stat)
}
else {
return a.localeCompare(b)
if (stat.isDirectory()) {
return walk(filePath, consumer, filter, true)
}
return filePath
})
}, concurrency)

const result: Array<string> = addRootToResult ? [dirPath] : []
for (let item of list) {
if (item != null) {
if (Array.isArray(item)) {
result.push.apply(result, item)
}
else {
result.push(item)
}
}
list.sort((a, b) => {
// files before directories
if (Array.isArray(a) && Array.isArray(b)) {
return 0
}
else if (a == null || Array.isArray(a)) {
return 1
}
else if (b == null || Array.isArray(b)) {
return -1
}
else {
return a.localeCompare(b)
}
})

const result: Array<string> = addRootToResult ? [dirPath] : []
for (let item of list) {
if (item != null) {
if (Array.isArray(item)) {
result.push.apply(result, item)
}
return result
})
else {
result.push(item)
}
}
}
return result
}

export async function createAsarArchive(src: string, resourcesPath: string, options: AsarOptions, filter: Filter): Promise<any> {
Expand Down
Loading

0 comments on commit a33e004

Please sign in to comment.