@zenstackhq/sdk
Advanced tools
Comparing version 1.0.0-alpha.102 to 1.0.0-alpha.110
@@ -1,5 +0,13 @@ | ||
import { Project } from 'ts-morph'; | ||
import { CompilerOptions, Project } from 'ts-morph'; | ||
/** | ||
* Creates a TS code generation project | ||
*/ | ||
export declare function createProject(options?: CompilerOptions): Project; | ||
/** | ||
* Persists a TS project to disk. | ||
*/ | ||
export declare function saveProject(project: Project): Promise<void>; | ||
/** | ||
* Emit a TS project to JS files. | ||
*/ | ||
export declare function emitProject(project: Project, format?: boolean): Promise<void>; | ||
export declare function emitProject(project: Project): Promise<void>; |
@@ -15,4 +15,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.emitProject = void 0; | ||
exports.emitProject = exports.saveProject = exports.createProject = void 0; | ||
const prettier_1 = __importDefault(require("prettier")); | ||
const ts_morph_1 = require("ts-morph"); | ||
const types_1 = require("./types"); | ||
const formatOptions = { | ||
@@ -42,12 +44,42 @@ trailingComma: 'all', | ||
/** | ||
* Creates a TS code generation project | ||
*/ | ||
function createProject(options) { | ||
return new ts_morph_1.Project({ | ||
compilerOptions: Object.assign({ target: ts_morph_1.ScriptTarget.ES2016, module: ts_morph_1.ModuleKind.CommonJS, esModuleInterop: true, declaration: true, strict: true, skipLibCheck: true, noEmitOnError: true }, options), | ||
}); | ||
} | ||
exports.createProject = createProject; | ||
/** | ||
* Persists a TS project to disk. | ||
*/ | ||
function saveProject(project) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield Promise.all(project.getSourceFiles().map((sf) => __awaiter(this, void 0, void 0, function* () { | ||
yield formatFile(sf); | ||
}))); | ||
yield project.save(); | ||
}); | ||
} | ||
exports.saveProject = saveProject; | ||
/** | ||
* Emit a TS project to JS files. | ||
*/ | ||
function emitProject(project, format = true) { | ||
function emitProject(project) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (format) { | ||
yield Promise.all(project.getSourceFiles().map((sf) => __awaiter(this, void 0, void 0, function* () { | ||
yield formatFile(sf); | ||
}))); | ||
const errors = project.getPreEmitDiagnostics().filter((d) => d.getCategory() === ts_morph_1.DiagnosticCategory.Error); | ||
if (errors.length > 0) { | ||
console.error('Error compiling generated code:'); | ||
console.error(project.formatDiagnosticsWithColorAndContext(errors.slice(0, 10))); | ||
yield project.save(); | ||
throw new types_1.PluginError(`Error compiling generated code`); | ||
} | ||
yield project.emit(); | ||
const result = yield project.emit(); | ||
const emitErrors = result.getDiagnostics().filter((d) => d.getCategory() === ts_morph_1.DiagnosticCategory.Error); | ||
if (emitErrors.length > 0) { | ||
console.error('Some generated code is not emitted:'); | ||
console.error(project.formatDiagnosticsWithColorAndContext(emitErrors.slice(0, 10))); | ||
yield project.save(); | ||
throw new types_1.PluginError(`Error emitting generated code`); | ||
} | ||
}); | ||
@@ -54,0 +86,0 @@ } |
{ | ||
"name": "@zenstackhq/sdk", | ||
"version": "1.0.0-alpha.102", | ||
"version": "1.0.0-alpha.110", | ||
"description": "ZenStack plugin development SDK", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
"ts-morph": "^16.0.0", | ||
"@zenstackhq/language": "1.0.0-alpha.102" | ||
"@zenstackhq/language": "1.0.0-alpha.110" | ||
}, | ||
@@ -20,0 +20,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
59538
889
1
+ Added@zenstackhq/language@1.0.0-alpha.110(transitive)
- Removed@zenstackhq/language@1.0.0-alpha.102(transitive)