@vuedx/projectconfig
Advanced tools
Comparing version 0.7.2-insiders-1623402835.0 to 0.7.2-insiders-1630600136.0
@@ -5,8 +5,10 @@ var version = "0.7.1"; | ||
moduleName: string; | ||
/** Use '*' for namespace imports. */ | ||
exportName?: string; | ||
} | ||
interface ProjectPreferences { | ||
componentsDirectories: string[]; | ||
script: { | ||
mode: 'setup' | 'setup-ref' | 'normal'; | ||
mode: 'setup' | 'normal'; | ||
language: 'js' | 'ts'; | ||
@@ -23,11 +25,50 @@ }; | ||
} | ||
interface ProjectConfigNormalized { | ||
globalComponents: Array<string | Record<string, string | ImportSource>>; | ||
preferences: ProjectPreferences; | ||
} | ||
interface ProjectConfig { | ||
globalComponents?: Array<string | Record<string, string | ImportSource>>; | ||
globalDirectives?: Array<string | Record<string, string | ImportSource>>; | ||
preferences?: Partial<ProjectPreferences>; | ||
} | ||
interface ResolvedProjectConfig { | ||
globalComponents: Record<string, ImportSource[]>; | ||
globalDirectives: Record<string, ImportSource[]>; | ||
preferences: ProjectPreferences; | ||
} | ||
export { ImportSource, ProjectConfig, ProjectConfigNormalized, ProjectPreferences, version }; | ||
interface FileWatcher { | ||
close(): void; | ||
} | ||
declare enum FileWatcherEventKind { | ||
Created = 0, | ||
Changed = 1, | ||
Deleted = 2 | ||
} | ||
declare type FileWatcherCallback = (fileName: string, eventKind: FileWatcherEventKind) => void; | ||
declare type DirectoryWatcherCallback = (fileName: string) => void; | ||
interface FilesystemHost { | ||
readDirectory(rootDir: string, extensions: string[]): string[]; | ||
fileExists(path: string): boolean; | ||
readFile(path: string): string | undefined; | ||
watchFile(path: string, callback: FileWatcherCallback): FileWatcher; | ||
watchDirectory(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher; | ||
} | ||
declare class VueProject { | ||
protected readonly fs: FilesystemHost; | ||
readonly rootDir: string; | ||
readonly packageFile: string | null; | ||
readonly projectFile: string | null; | ||
static create(fs: FilesystemHost, rootDir: string): VueProject; | ||
private readonly watchers; | ||
private constructor(); | ||
private loadDependencies; | ||
dispose(): void; | ||
_dependencies: Record<string, string>; | ||
get dependencies(): Readonly<Record<string, string>>; | ||
private _config; | ||
get config(): Readonly<ResolvedProjectConfig>; | ||
private setConfig; | ||
get kind(): 'inferred' | 'configured'; | ||
} | ||
export { FilesystemHost, ProjectConfig, ProjectPreferences, ResolvedProjectConfig, VueProject, version }; |
209
lib/index.js
@@ -5,5 +5,214 @@ 'use strict'; | ||
const Path = require('path'); | ||
const shared = require('@vuedx/shared'); | ||
const JSON5 = require('json5'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
const Path__default = /*#__PURE__*/_interopDefaultLegacy(Path); | ||
const JSON5__default = /*#__PURE__*/_interopDefaultLegacy(JSON5); | ||
var version = "0.7.1"; | ||
const DEFAULT_PROJECT_CONFIG = { | ||
globalComponents: {}, | ||
globalDirectives: {}, | ||
preferences: { | ||
componentsDirectories: ['src/components'], | ||
script: { mode: 'normal', language: 'js' }, | ||
style: { language: 'css' }, | ||
template: { | ||
directiveSyntax: 'shorthand', | ||
propCase: 'camel', | ||
tagCase: 'auto', | ||
}, | ||
}, | ||
}; | ||
function deepDefaults(a, b) { | ||
if (b == null) | ||
return a; | ||
Object.keys(b).forEach((key) => { | ||
const valueA = a[key]; | ||
const valueB = b[key]; | ||
if (valueB === undefined) | ||
return; | ||
if (valueA == null || Array.isArray(valueB)) { | ||
a[key] = valueB; | ||
} | ||
else if (typeof valueA === 'object' && typeof valueB === 'object') { | ||
a[key] = deepDefaults(valueA, valueB); | ||
} | ||
else { | ||
a[key] = valueB; | ||
} | ||
}); | ||
return a; | ||
} | ||
var FileWatcherEventKind; | ||
(function (FileWatcherEventKind) { | ||
FileWatcherEventKind[FileWatcherEventKind["Created"] = 0] = "Created"; | ||
FileWatcherEventKind[FileWatcherEventKind["Changed"] = 1] = "Changed"; | ||
FileWatcherEventKind[FileWatcherEventKind["Deleted"] = 2] = "Deleted"; | ||
})(FileWatcherEventKind || (FileWatcherEventKind = {})); | ||
function findNearestFile(fs, dir, name) { | ||
let cur = shared.toPosixPath(dir); | ||
while (cur.length > 1) { | ||
const fileName = Path__default['default'].posix.resolve(cur, name); | ||
if (fs.fileExists(fileName)) | ||
return fileName; | ||
cur = Path__default['default'].posix.dirname(cur); | ||
} | ||
return null; | ||
} | ||
function resolveComponents(rootDir, resources) { | ||
const components = {}; | ||
const add = (name, source) => { | ||
var _a; | ||
const sources = (_a = components[name]) !== null && _a !== void 0 ? _a : (components[name] = []); | ||
if (sources.some((item) => item.moduleName === source.moduleName && | ||
item.exportName === source.exportName)) { | ||
return; // duplicate | ||
} | ||
sources.push(source); | ||
}; | ||
for (const resource of resources) { | ||
if (shared.isString(resource)) { | ||
add(shared.getComponentName(resource), { | ||
moduleName: resolve(resource), | ||
}); | ||
} | ||
else | ||
Object.entries(resource).forEach(([key, value]) => { | ||
add(key, shared.isString(value) ? { moduleName: resolve(value) } : value); | ||
}); | ||
} | ||
return components; | ||
function resolve(resource) { | ||
if (resource.startsWith('.')) | ||
return Path__default['default'].posix.resolve(rootDir, resource); | ||
else | ||
return resource; | ||
} | ||
} | ||
function resolveDirectives(rootDir, resources) { | ||
const directives = {}; | ||
const add = (name, source) => { | ||
var _a; | ||
const sources = (_a = directives[name]) !== null && _a !== void 0 ? _a : (directives[name] = []); | ||
if (sources.some((item) => item.moduleName === source.moduleName && | ||
item.exportName === source.exportName)) { | ||
return; // duplicate | ||
} | ||
sources.push(source); | ||
}; | ||
for (const resource of resources) { | ||
if (shared.isString(resource)) ; | ||
else | ||
Object.entries(resource).forEach(([key, value]) => { | ||
add(key, shared.isString(value) ? { moduleName: resolve(value) } : value); | ||
}); | ||
} | ||
return directives; | ||
function resolve(resource) { | ||
if (resource.startsWith('.')) | ||
return Path__default['default'].posix.resolve(rootDir, resource); | ||
else | ||
return resource; | ||
} | ||
} | ||
class VueProject { | ||
constructor(fs, rootDir, packageFile = null, projectFile = null) { | ||
this.fs = fs; | ||
this.rootDir = rootDir; | ||
this.packageFile = packageFile; | ||
this.projectFile = projectFile; | ||
this.watchers = []; | ||
this._dependencies = {}; | ||
this._config = DEFAULT_PROJECT_CONFIG; | ||
if (projectFile != null) { | ||
this.watchers.push(fs.watchFile(projectFile, (fileName, event) => { | ||
if (event === FileWatcherEventKind.Changed) { | ||
const content = fs.readFile(fileName); | ||
if (content != null) { | ||
try { | ||
this.setConfig(JSON5__default['default'].parse(content)); | ||
} | ||
catch (error) { | ||
// FIXME: Store error for diagnostics usage. | ||
} | ||
} | ||
} | ||
})); | ||
} | ||
if (packageFile != null) { | ||
this.watchers.push(fs.watchFile(packageFile, (fileName, event) => { | ||
if (event === FileWatcherEventKind.Changed) { | ||
const content = fs.readFile(fileName); | ||
if (content != null) { | ||
try { | ||
const pkg = JSON.parse(content); | ||
this.loadDependencies({ | ||
...pkg.devDependencies, | ||
...pkg.dependencies, | ||
}); | ||
} | ||
catch (error) { | ||
// FIXME: Store error for diagnostics usage. | ||
} | ||
} | ||
} | ||
})); | ||
} | ||
} | ||
static create(fs, rootDir) { | ||
const projectFile = Path__default['default'].posix.resolve(rootDir, 'vueconfig.json'); | ||
const packageFile = findNearestFile(fs, rootDir, 'package.json'); | ||
return new VueProject(fs, rootDir, packageFile, fs.fileExists(projectFile) ? projectFile : null); | ||
} | ||
loadDependencies(dependencies) { | ||
if (this.packageFile == null) | ||
return; | ||
const modulesDir = Path__default['default'].posix.resolve(Path__default['default'].posix.dirname(this.packageFile), 'node_modules'); | ||
Object.keys(dependencies).forEach((packageName) => { | ||
const fileName = Path__default['default'].posix.resolve(modulesDir, packageName, 'package.json'); | ||
if (this.fs.fileExists(fileName)) { | ||
this._dependencies[packageName] = JSON.parse(fileName).version; | ||
} | ||
}); | ||
} | ||
dispose() { | ||
this.watchers.forEach((watcher) => watcher.close()); | ||
this.watchers.length = 0; | ||
} | ||
get dependencies() { | ||
return this._dependencies; | ||
} | ||
get config() { | ||
return this._config; | ||
} | ||
setConfig(config) { | ||
this._config = { | ||
globalComponents: this._config.globalComponents, | ||
globalDirectives: this._config.globalDirectives, | ||
preferences: deepDefaults(this._config.preferences, config.preferences), | ||
}; | ||
if (config.globalComponents != null) { | ||
this._config.globalComponents = resolveComponents(this.rootDir, config.globalComponents); | ||
} | ||
if (config.globalDirectives != null) { | ||
this._config.globalDirectives = resolveDirectives(this.rootDir, config.globalDirectives); | ||
} | ||
} | ||
get kind() { | ||
return this.projectFile == null ? 'inferred' : 'configured'; | ||
} | ||
} | ||
exports.VueProject = VueProject; | ||
exports.version = version; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@vuedx/projectconfig", | ||
"version": "0.7.2-insiders-1623402835.0", | ||
"version": "0.7.2-insiders-1630600136.0", | ||
"description": "TypeScript plugin for Vue", | ||
@@ -34,3 +34,7 @@ "main": "lib/index.js", | ||
}, | ||
"homepage": "https://github.com/znck/vue-developer-experience#readme" | ||
"homepage": "https://github.com/znck/vue-developer-experience#readme", | ||
"dependencies": { | ||
"@vuedx/shared": "0.7.4-insiders-1630600136.0", | ||
"json5": "^2.2.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35780
578
2
1
+ Addedjson5@^2.2.0
+ Added@sentry/core@5.30.0(transitive)
+ Added@sentry/hub@5.30.0(transitive)
+ Added@sentry/minimal@5.30.0(transitive)
+ Added@sentry/node@5.30.0(transitive)
+ Added@sentry/tracing@5.30.0(transitive)
+ Added@sentry/types@5.30.0(transitive)
+ Added@sentry/utils@5.30.0(transitive)
+ Added@vuedx/shared@0.7.4-insiders-1630600136.0(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedcookie@0.4.2(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedlru_map@0.3.3(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-unique-machine-id@1.1.0(transitive)
+ Addedtslib@1.14.1(transitive)
+ Addeduuid@3.4.0(transitive)