Use latest extension support with good locking (#2718)

* Use latest extension support with good locking

* dispose of EM on shutdown

* made sure that it exits
This commit is contained in:
Garrett Serack 2017-11-18 17:25:35 -08:00 коммит произвёл Johannes Bader
Родитель b3dcc28d08
Коммит 6c78ba135e
7 изменённых файлов: 21 добавлений и 14 удалений

Просмотреть файл

@ -16,7 +16,7 @@ Import
# Run AutoRest from the original current directory.
echo info "Queuing up: AutoRest #{args.join(' ')}"
args = args.concat("--clear-output-folder", "--version=#{basefolder}/src/autorest-core") if args[0] != "--reset"
execute "node #{basefolder}/src/autorest/dist/app.js #{args.map((a) -> "\"#{a}\"").join(' ')} --no-upgrade-check" , {silent:true, ignoreexitcode: ignoreexitcode || false}, (code,stdout,stderr) ->
execute "node #{basefolder}/src/autorest/dist/app.js #{args.map((a) -> "\"#{a}\"").join(' ')} --no-upgrade-check --version=#{basefolder}/src/autorest-core" , {silent:true, ignoreexitcode: ignoreexitcode || false}, (code,stdout,stderr) ->
return done(code,stdout,stderr)
typescriptProjectFolders: ()->
@ -135,7 +135,7 @@ task 'testci', "more", [], (done) ->
await run "test", defer _
## CLEAN
await autorest ["--reset"], defer code,stdout,stderr
await autorest ["--reset","--allow-no-input"], defer code,stdout,stderr
## REGRESSION TEST
global.verbose = false

Просмотреть файл

@ -1,6 +1,6 @@
task 'regenerate', 'regenerate samples', (done) ->
execute "node #{basefolder}/src/autorest/dist/app.js --reset --no-upgrade-check --allow-no-input" , {silent:false }, (code,stdout,stderr) ->
execute "node #{basefolder}/src/autorest/dist/app.js --reset --no-upgrade-check --allow-no-input --version=#{basefolder}/src/autorest-core --verbose --debug" , {silent:false }, (code,stdout,stderr) ->
count = 0
# source 'Samples/*/**/readme.md'
source 'Samples/*/**/readme.md'

Просмотреть файл

@ -558,7 +558,7 @@ export class Configuration {
return blocks;
}
private extensionManager: LazyPromise<ExtensionManager> = new LazyPromise<ExtensionManager>(() => ExtensionManager.Create(join(process.env["autorest.home"] || require("os").homedir(), ".autorest")));
private static extensionManager: LazyPromise<ExtensionManager> = new LazyPromise<ExtensionManager>(() => ExtensionManager.Create(join(process.env["autorest.home"] || require("os").homedir(), ".autorest")));
private async DesugarRawConfig(configs: any): Promise<any> {
// shallow copy
@ -576,7 +576,7 @@ export class Configuration {
use = [use];
}
if (Array.isArray(use)) {
const extMgr = await this.extensionManager;
const extMgr = await Configuration.extensionManager;
for (const useEntry of use) {
if (typeof useEntry === "string") {
// attempt <package>@<version> interpretation
@ -604,6 +604,13 @@ export class Configuration {
public static async shutdown() {
AutoRestExtension.killAll();
// once we shutdown those extensions, we should shutdown the EM too.
const extMgr = await Configuration.extensionManager;
extMgr.dispose();
// but if someone goes to use that, we're going to need a new instance (since the shared lock will be gone in the one we disposed.)
Configuration.extensionManager = new LazyPromise<ExtensionManager>(() => ExtensionManager.Create(join(process.env["autorest.home"] || require("os").homedir(), ".autorest")))
for (const each in loadedExtensions) {
const ext = loadedExtensions[each];
if (ext.autorestExtension.hasValue) {
@ -677,7 +684,7 @@ export class Configuration {
await addSegments(blocks);
}
// 5. resolve extensions
const extMgr = await this.extensionManager;
const extMgr = await Configuration.extensionManager;
const addedExtensions = new Set<string>();
const viewsToHandle: ConfigurationView[] = [createView()];
while (viewsToHandle.length > 0) {

Просмотреть файл

@ -22,7 +22,7 @@ export module IAutoRestPluginInitiator_Types {
export const GetValue = new RequestType2<string, string, any, Error, void>("GetValue");
export const ListInputs = new RequestType1<string, string[], Error, void>("ListInputs");
export const WriteFile = new NotificationType4<string, string, string, Mapping[] | RawSourceMap | undefined, void>("WriteFile");
export const Message = new NotificationType4<string, Message, SmartPosition | undefined, string | undefined, void>("Message");
/* @internal */export const Message = new NotificationType4<string, Message, SmartPosition | undefined, string | undefined, void>("Message");
}
export interface IAutoRestPluginInitiator {
ReadFile(sessionId: string, filename: string): Promise<string>;

Просмотреть файл

@ -24,7 +24,7 @@
"autorest-language-service": "dist/language-service/language-service.js"
},
"scripts": {
"test": "./node_modules/.bin/mocha ./dist/test --timeout 500000",
"test": "./node_modules/.bin/mocha ./dist/test --timeout 50000",
"build": "tsc -p . & dts-generator --name autorest-core --project . --out ../autorest/interfaces/autorest-core.d.ts --exclude \"test/**/*\" --exclude \"node_modules/**/*.d.ts\" --exclude \"lib/source-map/**\" --exclude \"lib/pipeline/**\" --exclude \"lib/parsing/**\" --exclude \"lib/data-store/**\" --exclude \"lib/ref/yaml.ts\" --extern ./source-maps.d.ts",
"static-link": "static-link",
"postinstall": "node ./post-install --force",
@ -50,7 +50,7 @@
"entrypoints": [],
"dependencies": {
"@microsoft.azure/async-io": "~2.0.7",
"@microsoft.azure/extension": "^2.0.4",
"@microsoft.azure/extension": "^2.0.18",
"vscode-languageserver": "3.4.3",
"commonmark": "^0.27.0",
"file-url": "^2.0.2",
@ -69,4 +69,4 @@
},
"patch": "const fs = require(`fs`); let txt = fs.readFileSync('./node_modules/npm/lib/install/action/extract.js','utf8').replace(`const ENABLE_WORKERS = process.platform === 'darwin'`, `const ENABLE_WORKERS = false;`); fs.writeFileSync('./node_modules/npm/lib/install/action/extract.js', txt ); txt = fs.readFileSync(`./node_modules/npm/lib/npm.js`,`utf8`).replace(`var j = parseJSON(fs.readFileSync(`, `var j = require(path.join(__dirname, '../package.json'));` ).replace(`path.join(__dirname, '../package.json')) + '')`,``); fs.writeFileSync(`./node_modules/npm/lib/npm.js`, txt ); txt = fs.readFileSync('./node_modules/npm/lib/pack.js','utf8').replace(`require.main.filename`, `require.resolve('../bin/npm-cli.js')`); fs.writeFileSync('./node_modules/npm/lib/pack.js', txt );"
}
}
}

2
src/autorest/interfaces/autorest-core.d.ts поставляемый
Просмотреть файл

@ -518,7 +518,7 @@ export class Configuration {
private configFileOrFolderUri;
constructor(fileSystem?: IFileSystem, configFileOrFolderUri?: string | undefined);
private ParseCodeBlocks(configFile, contextConfig, scope);
private extensionManager;
private static extensionManager;
private DesugarRawConfig(configs);
private DesugarRawConfigs(configs);
static shutdown(): Promise<void>;

Просмотреть файл

@ -50,11 +50,11 @@
"entrypoints": [],
"dependencies": {
"@microsoft.azure/async-io": "~2.0.7",
"@microsoft.azure/extension": "^2.0.4",
"@microsoft.azure/tasks": "~2.0.12",
"@microsoft.azure/extension": "^2.0.18",
"@microsoft.azure/tasks": "~2.0.15",
"semver": "^5.3.0",
"chalk": "2.3.0"
},
"patch": "const fs = require(`fs`); let txt = fs.readFileSync('./node_modules/npm/lib/install/action/extract.js','utf8').replace(`const ENABLE_WORKERS = process.platform === 'darwin'`, `const ENABLE_WORKERS = false;`); fs.writeFileSync('./node_modules/npm/lib/install/action/extract.js', txt ); txt = fs.readFileSync(`./node_modules/npm/lib/npm.js`,`utf8`).replace(`var j = parseJSON(fs.readFileSync(`, `var j = require(path.join(__dirname, '../package.json'));` ).replace(`path.join(__dirname, '../package.json')) + '')`,``); fs.writeFileSync(`./node_modules/npm/lib/npm.js`, txt ); txt = fs.readFileSync('./node_modules/npm/lib/pack.js','utf8').replace(`require.main.filename`, `require.resolve('../bin/npm-cli.js')`); fs.writeFileSync('./node_modules/npm/lib/pack.js', txt ); "
}
}
}