Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 08b302bd46 | |||
| 747a67d790 | |||
| 6ec05d6b4a | |||
| 77df2743c5 |
20
changelog.md
20
changelog.md
@@ -1,5 +1,25 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-12-31 - 3.19.1 - fix(intellisense)
|
||||
Debounce TypeScript/JavaScript IntelliSense processing and cache missing packages to reduce work and noisy logs
|
||||
|
||||
- Add 500ms debounce in editor workspace to avoid parsing on every keystroke
|
||||
- Introduce notFoundPackages cache to skip repeated filesystem checks for packages without types
|
||||
- Clear not-found cache when scanning node_modules so newly installed packages are re-detected
|
||||
- Remove noisy console logs and make file/directory read errors non-fatal (ignored)
|
||||
- Simplify processContentChange signature (removed optional filePath) and remove manual diagnostic refresh logic
|
||||
|
||||
## 2025-12-31 - 3.19.0 - feat(dees-editor-workspace)
|
||||
improve TypeScript IntelliSense, auto-run workspace init commands, and watch node_modules for new packages
|
||||
|
||||
- Execute an onInit command from /npmextra.json on workspace initialization (e.g., run pnpm install).
|
||||
- Add npmextra.json and an import test file (importtest.ts) plus a sample dependency in the scaffold to test package imports.
|
||||
- Add node_modules watcher with debounce to auto-scan and load package types after installs.
|
||||
- Enhance TypeScript IntelliSense: recursively load all .d.ts files from packages and @types packages, add package.json as extra lib, and log progress/errors for debugging.
|
||||
- Change processContentChange signature to accept optional filePath and trigger a diagnostic refresh when new types are loaded.
|
||||
- Expose scanAndLoadNewPackageTypes to scan top-level and scoped packages and load their types.
|
||||
- Add start/stop logic for the node_modules watcher in workspace lifecycle to avoid leaks and handle cleanup.
|
||||
|
||||
## 2025-12-31 - 3.18.0 - feat(filetree)
|
||||
add filesystem watch support to WebContainer environment and auto-refresh file tree; improve icon handling and context menu behavior
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@design.estate/dees-catalog",
|
||||
"version": "3.18.0",
|
||||
"version": "3.19.1",
|
||||
"private": false,
|
||||
"description": "A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.",
|
||||
"main": "dist_ts_web/index.js",
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@design.estate/dees-catalog',
|
||||
version: '3.18.0',
|
||||
version: '3.19.1',
|
||||
description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '@design.estate/dees-element';
|
||||
import * as domtools from '@design.estate/dees-domtools';
|
||||
import { themeDefaultStyles } from '../../00theme.js';
|
||||
import type { IExecutionEnvironment } from '../../00group-runtime/index.js';
|
||||
import type { IExecutionEnvironment, IFileWatcher } from '../../00group-runtime/index.js';
|
||||
import { WebContainerEnvironment } from '../../00group-runtime/index.js';
|
||||
import type { FileSystemTree } from '@webcontainer/api';
|
||||
import '../dees-editor-monaco/dees-editor-monaco.js';
|
||||
@@ -56,6 +56,9 @@ export class DeesEditorWorkspace extends DeesElement {
|
||||
build: 'tsc',
|
||||
dev: 'tsc --watch',
|
||||
},
|
||||
dependencies: {
|
||||
'@push.rocks/smartpromise': '^4.2.3',
|
||||
},
|
||||
devDependencies: {
|
||||
typescript: '^5.0.0',
|
||||
},
|
||||
@@ -65,6 +68,19 @@ export class DeesEditorWorkspace extends DeesElement {
|
||||
),
|
||||
},
|
||||
},
|
||||
'npmextra.json': {
|
||||
file: {
|
||||
contents: JSON.stringify(
|
||||
{
|
||||
deesEditorWorkspace: {
|
||||
onInit: 'pnpm install',
|
||||
},
|
||||
},
|
||||
null,
|
||||
2
|
||||
),
|
||||
},
|
||||
},
|
||||
'tsconfig.json': {
|
||||
file: {
|
||||
contents: JSON.stringify(
|
||||
@@ -125,6 +141,28 @@ export function formatName(name: string): string {
|
||||
export function createUser(firstName: string, lastName: string): IUser {
|
||||
return { firstName, lastName };
|
||||
}
|
||||
`,
|
||||
},
|
||||
},
|
||||
'importtest.ts': {
|
||||
file: {
|
||||
contents: `// Test npm package imports
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
// This should have IntelliSense showing defer() method
|
||||
const deferred = smartpromise.defer<string>();
|
||||
|
||||
// Test using the deferred promise
|
||||
async function testSmartPromise() {
|
||||
setTimeout(() => {
|
||||
deferred.resolve('Hello from smartpromise!');
|
||||
}, 100);
|
||||
|
||||
const result = await deferred.promise;
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
testSmartPromise();
|
||||
`,
|
||||
},
|
||||
},
|
||||
@@ -199,6 +237,11 @@ export function createUser(firstName: string, lastName: string): IUser {
|
||||
private intelliSenseManager: TypeScriptIntelliSenseManager | null = null;
|
||||
private intelliSenseInitialized: boolean = false;
|
||||
|
||||
// node_modules watcher for auto-loading types
|
||||
private nodeModulesWatcher: IFileWatcher | null = null;
|
||||
private nodeModulesDebounceTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
private intelliSenseDebounceTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
// Auto-save functionality
|
||||
@state()
|
||||
accessor autoSave: boolean = false;
|
||||
@@ -753,6 +796,7 @@ export function createUser(firstName: string, lastName: string): IUser {
|
||||
clearInterval(this.autoSaveInterval);
|
||||
this.autoSaveInterval = null;
|
||||
}
|
||||
this.stopNodeModulesWatcher();
|
||||
}
|
||||
|
||||
public async firstUpdated() {
|
||||
@@ -783,6 +827,10 @@ export function createUser(firstName: string, lastName: string): IUser {
|
||||
} else if (!this.executionEnvironment.ready) {
|
||||
await this.executionEnvironment.init();
|
||||
}
|
||||
|
||||
// Execute onInit command from npmextra.json if present
|
||||
await this.executeOnInitCommand();
|
||||
|
||||
// IntelliSense is initialized lazily when first file is opened (Monaco loads on demand)
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize workspace:', error);
|
||||
@@ -793,6 +841,34 @@ export function createUser(firstName: string, lastName: string): IUser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute onInit command from npmextra.json if present
|
||||
* This allows automatic setup like `pnpm install` on workspace initialization
|
||||
*/
|
||||
private async executeOnInitCommand(): Promise<void> {
|
||||
if (!this.executionEnvironment) return;
|
||||
|
||||
try {
|
||||
if (await this.executionEnvironment.exists('/npmextra.json')) {
|
||||
const content = await this.executionEnvironment.readFile('/npmextra.json');
|
||||
const config = JSON.parse(content);
|
||||
const onInit = config?.deesEditorWorkspace?.onInit;
|
||||
|
||||
if (onInit && typeof onInit === 'string') {
|
||||
console.log('Executing onInit command:', onInit);
|
||||
// Parse command and args
|
||||
const [cmd, ...args] = onInit.split(' ');
|
||||
const process = await this.executionEnvironment.spawn(cmd, args);
|
||||
// Wait for completion
|
||||
const exitCode = await process.exit;
|
||||
console.log('onInit command completed with exit code:', exitCode);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to execute onInit command:', error);
|
||||
}
|
||||
}
|
||||
|
||||
private async initializeIntelliSense(): Promise<void> {
|
||||
if (!this.executionEnvironment) return;
|
||||
if (this.intelliSenseInitialized) return;
|
||||
@@ -816,6 +892,51 @@ export function createUser(firstName: string, lastName: string): IUser {
|
||||
|
||||
// Set up marker listener for Problems panel
|
||||
this.setupMarkerListener();
|
||||
|
||||
// Start watching node_modules for package installations
|
||||
this.startNodeModulesWatcher();
|
||||
|
||||
// Initial scan for any existing packages
|
||||
await this.intelliSenseManager.scanAndLoadNewPackageTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch node_modules for changes (e.g., after pnpm install)
|
||||
* and automatically load types for new packages
|
||||
*/
|
||||
private startNodeModulesWatcher(): void {
|
||||
if (!this.executionEnvironment || this.nodeModulesWatcher) return;
|
||||
|
||||
try {
|
||||
this.nodeModulesWatcher = this.executionEnvironment.watch(
|
||||
'/node_modules',
|
||||
(_event, _filename) => {
|
||||
// Debounce - pnpm install creates many file changes
|
||||
if (this.nodeModulesDebounceTimeout) {
|
||||
clearTimeout(this.nodeModulesDebounceTimeout);
|
||||
}
|
||||
this.nodeModulesDebounceTimeout = setTimeout(async () => {
|
||||
if (this.intelliSenseManager) {
|
||||
await this.intelliSenseManager.scanAndLoadNewPackageTypes();
|
||||
}
|
||||
}, 2000); // 2 second debounce for package installation
|
||||
},
|
||||
{ recursive: true }
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn('Could not watch node_modules:', error);
|
||||
}
|
||||
}
|
||||
|
||||
private stopNodeModulesWatcher(): void {
|
||||
if (this.nodeModulesWatcher) {
|
||||
this.nodeModulesWatcher.stop();
|
||||
this.nodeModulesWatcher = null;
|
||||
}
|
||||
if (this.nodeModulesDebounceTimeout) {
|
||||
clearTimeout(this.nodeModulesDebounceTimeout);
|
||||
this.nodeModulesDebounceTimeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async handleFileSelect(e: CustomEvent<{ path: string; name: string }>) {
|
||||
@@ -909,10 +1030,15 @@ export function createUser(firstName: string, lastName: string): IUser {
|
||||
...this.openFiles.slice(fileIndex + 1),
|
||||
];
|
||||
|
||||
// Process content for IntelliSense (TypeScript/JavaScript files)
|
||||
// Process content for IntelliSense (debounced to avoid parsing on every keystroke)
|
||||
const language = this.getLanguageFromPath(this.activeFilePath);
|
||||
if (this.intelliSenseManager && (language === 'typescript' || language === 'javascript')) {
|
||||
this.intelliSenseManager.processContentChange(newContent);
|
||||
if (this.intelliSenseDebounceTimeout) {
|
||||
clearTimeout(this.intelliSenseDebounceTimeout);
|
||||
}
|
||||
this.intelliSenseDebounceTimeout = setTimeout(() => {
|
||||
this.intelliSenseManager?.processContentChange(newContent);
|
||||
}, 500); // 500ms debounce
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ interface IMonacoTypeScriptAPI {
|
||||
*/
|
||||
export class TypeScriptIntelliSenseManager {
|
||||
private loadedLibs: Set<string> = new Set();
|
||||
private notFoundPackages: Set<string> = new Set(); // Packages checked but not found
|
||||
private monacoInstance: typeof monaco | null = null;
|
||||
private executionEnvironment: IExecutionEnvironment | null = null;
|
||||
|
||||
@@ -174,13 +175,19 @@ export class TypeScriptIntelliSenseManager {
|
||||
public async loadTypesForPackage(packageName: string): Promise<void> {
|
||||
if (!this.monacoInstance || !this.executionEnvironment) return;
|
||||
if (this.loadedLibs.has(packageName)) return;
|
||||
if (this.notFoundPackages.has(packageName)) return; // Skip packages we already checked
|
||||
|
||||
try {
|
||||
const typesLoaded = await this.tryLoadPackageTypes(packageName);
|
||||
let typesLoaded = await this.tryLoadPackageTypes(packageName);
|
||||
if (!typesLoaded) {
|
||||
await this.tryLoadAtTypesPackage(packageName);
|
||||
typesLoaded = await this.tryLoadAtTypesPackage(packageName);
|
||||
}
|
||||
if (typesLoaded) {
|
||||
this.loadedLibs.add(packageName);
|
||||
} else {
|
||||
// Cache that this package wasn't found to avoid repeated filesystem checks
|
||||
this.notFoundPackages.add(packageName);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`Failed to load types for ${packageName}:`, error);
|
||||
}
|
||||
@@ -195,26 +202,25 @@ export class TypeScriptIntelliSenseManager {
|
||||
try {
|
||||
// Check package.json for types field
|
||||
const packageJsonPath = `${basePath}/package.json`;
|
||||
if (await this.executionEnvironment.exists(packageJsonPath)) {
|
||||
const packageJson = JSON.parse(
|
||||
await this.executionEnvironment.readFile(packageJsonPath)
|
||||
);
|
||||
const packageJsonExists = await this.executionEnvironment.exists(packageJsonPath);
|
||||
|
||||
if (packageJsonExists) {
|
||||
const packageJsonContent = await this.executionEnvironment.readFile(packageJsonPath);
|
||||
const packageJson = JSON.parse(packageJsonContent);
|
||||
|
||||
// Add package.json to Monaco so TypeScript can resolve the types field
|
||||
ts.typescriptDefaults.addExtraLib(packageJsonContent, `file://${packageJsonPath}`);
|
||||
|
||||
const typesPath = packageJson.types || packageJson.typings;
|
||||
if (typesPath) {
|
||||
const fullTypesPath = `${basePath}/${typesPath}`;
|
||||
if (await this.executionEnvironment.exists(fullTypesPath)) {
|
||||
const content = await this.executionEnvironment.readFile(fullTypesPath);
|
||||
ts.typescriptDefaults.addExtraLib(
|
||||
content,
|
||||
`file://${fullTypesPath}`
|
||||
);
|
||||
// Load all .d.ts files from the package, not just the entry point
|
||||
// Modern packages often have multiple declaration files with imports
|
||||
await this.loadAllDtsFilesFromPackage(basePath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try common locations
|
||||
// Try common locations - if any exist, load all .d.ts files
|
||||
const commonPaths = [
|
||||
`${basePath}/index.d.ts`,
|
||||
`${basePath}/dist/index.d.ts`,
|
||||
@@ -223,24 +229,62 @@ export class TypeScriptIntelliSenseManager {
|
||||
|
||||
for (const dtsPath of commonPaths) {
|
||||
if (await this.executionEnvironment.exists(dtsPath)) {
|
||||
const content = await this.executionEnvironment.readFile(dtsPath);
|
||||
ts.typescriptDefaults.addExtraLib(
|
||||
content,
|
||||
`file://${dtsPath}`
|
||||
);
|
||||
await this.loadAllDtsFilesFromPackage(basePath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error(`Failed to load package types for ${packageName}:`, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async tryLoadAtTypesPackage(packageName: string): Promise<boolean> {
|
||||
/**
|
||||
* Recursively load all .d.ts files from a package directory
|
||||
*/
|
||||
private async loadAllDtsFilesFromPackage(basePath: string): Promise<void> {
|
||||
const ts = this.tsApi;
|
||||
if (!this.executionEnvironment || !ts) return false;
|
||||
if (!this.executionEnvironment || !ts) return;
|
||||
|
||||
await this.loadDtsFilesFromDirectory(basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively load .d.ts files from a directory
|
||||
*/
|
||||
private async loadDtsFilesFromDirectory(dirPath: string): Promise<void> {
|
||||
const ts = this.tsApi;
|
||||
if (!this.executionEnvironment || !ts) return;
|
||||
|
||||
try {
|
||||
const entries = await this.executionEnvironment.readDir(dirPath);
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = dirPath === '/' ? `/${entry.name}` : `${dirPath}/${entry.name}`;
|
||||
|
||||
// Skip nested node_modules (shouldn't happen in a package but be safe)
|
||||
if (entry.name === 'node_modules') continue;
|
||||
|
||||
if (entry.type === 'directory') {
|
||||
await this.loadDtsFilesFromDirectory(fullPath);
|
||||
} else if (entry.type === 'file' && entry.name.endsWith('.d.ts')) {
|
||||
try {
|
||||
const content = await this.executionEnvironment.readFile(fullPath);
|
||||
ts.typescriptDefaults.addExtraLib(content, `file://${fullPath}`);
|
||||
} catch {
|
||||
// Ignore files that can't be read
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Directory might not be readable
|
||||
}
|
||||
}
|
||||
|
||||
private async tryLoadAtTypesPackage(packageName: string): Promise<boolean> {
|
||||
if (!this.executionEnvironment) return false;
|
||||
|
||||
// Handle scoped packages: @scope/package -> @types/scope__package
|
||||
const typesPackageName = packageName.startsWith('@')
|
||||
@@ -252,11 +296,8 @@ export class TypeScriptIntelliSenseManager {
|
||||
try {
|
||||
const indexPath = `${basePath}/index.d.ts`;
|
||||
if (await this.executionEnvironment.exists(indexPath)) {
|
||||
const content = await this.executionEnvironment.readFile(indexPath);
|
||||
ts.typescriptDefaults.addExtraLib(
|
||||
content,
|
||||
`file://${indexPath}`
|
||||
);
|
||||
// Load all .d.ts files from the @types package
|
||||
await this.loadAllDtsFilesFromPackage(basePath);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -270,10 +311,57 @@ export class TypeScriptIntelliSenseManager {
|
||||
*/
|
||||
public async processContentChange(content: string): Promise<void> {
|
||||
const imports = this.parseImports(content);
|
||||
|
||||
for (const packageName of imports) {
|
||||
if (!this.loadedLibs.has(packageName)) {
|
||||
await this.loadTypesForPackage(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan node_modules for packages and load types for any not yet loaded.
|
||||
* Called when node_modules changes (e.g., after pnpm install).
|
||||
*/
|
||||
public async scanAndLoadNewPackageTypes(): Promise<void> {
|
||||
if (!this.executionEnvironment) return;
|
||||
|
||||
// Clear not-found cache so newly installed packages can be detected
|
||||
this.notFoundPackages.clear();
|
||||
|
||||
try {
|
||||
// Check if node_modules exists
|
||||
if (!await this.executionEnvironment.exists('/node_modules')) return;
|
||||
|
||||
// Read top-level node_modules
|
||||
const entries = await this.executionEnvironment.readDir('/node_modules');
|
||||
|
||||
for (const entry of entries) {
|
||||
if (entry.type !== 'directory') continue;
|
||||
|
||||
if (entry.name.startsWith('@')) {
|
||||
// Scoped package - read subdirectories
|
||||
try {
|
||||
const scopedPath = `/node_modules/${entry.name}`;
|
||||
const scopedEntries = await this.executionEnvironment.readDir(scopedPath);
|
||||
for (const scopedEntry of scopedEntries) {
|
||||
if (scopedEntry.type === 'directory') {
|
||||
const packageName = `${entry.name}/${scopedEntry.name}`;
|
||||
await this.loadTypesForPackage(packageName);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Skip if we can't read scoped directory
|
||||
}
|
||||
} else if (!entry.name.startsWith('.')) {
|
||||
// Regular package
|
||||
await this.loadTypesForPackage(entry.name);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to scan node_modules:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a file model to Monaco for cross-file IntelliSense
|
||||
|
||||
Reference in New Issue
Block a user