diff --git a/src/app/core/code/code.service.ts b/src/app/core/code/code.service.ts index bf45d7241..ef39dc8f4 100644 --- a/src/app/core/code/code.service.ts +++ b/src/app/core/code/code.service.ts @@ -1,5 +1,7 @@ import { DOCUMENT } from '@angular/common'; -import { Inject, Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Injectable, inject } from '@angular/core'; +import { lastValueFrom } from 'rxjs'; import sdk from '@stackblitz/sdk'; import { getParameters } from 'codesandbox/lib/api/define'; @@ -16,13 +18,14 @@ import readme from './files/readme-cli'; import sandboxConfigJSON from './files/sandbox'; import startupServiceTS from './files/startup.service'; import tsconfigJSON from './files/tsconfig.json'; -import yarnLock from './files/yarn.lock'; import pkg from '../../../../package.json'; import { AppService } from '../app.service'; @Injectable({ providedIn: 'root' }) export class CodeService { - private document: Document; + private appSrv = inject(AppService); + private http = inject(HttpClient); + private document = inject(DOCUMENT); private get themePath(): string { return `node_modules/@delon/theme/${this.appSrv.theme}.css`; @@ -85,13 +88,6 @@ export class CodeService { return res; } - constructor( - private appSrv: AppService, - @Inject(DOCUMENT) document: NzSafeAny - ) { - this.document = document; - } - private get genStartupService(): string { return startupServiceTS({ ajvVersion: pkg.dependencies.ajv.substring(1) }); } @@ -132,7 +128,20 @@ export class CodeService { return `${code.replace(`@Component({`, `@Component({\n standalone: true,\n`)}`; } - openOnStackBlitz(title: string, appComponentCode: string): void { + private yarnLock?: string; + private async getYarnLock(): Promise { + if (this.yarnLock != null) return this.yarnLock; + try { + const res = await lastValueFrom(this.http.get('./assets/yarn.lock.txt', { responseType: 'text' })); + this.yarnLock = res; + return res; + } catch (ex) { + console.warn(`Unable to load yarn.lock file: ${ex}`); + } + return ''; + } + + async openOnStackBlitz(title: string, appComponentCode: string): Promise { appComponentCode = this.attachStandalone(appComponentCode); const res = this.parseCode(appComponentCode); const json = deepCopy(angularJSON); @@ -161,7 +170,7 @@ export class CodeService { null, 2 ), - 'yarn.lock': yarnLock, + 'yarn.lock': await this.getYarnLock(), 'angular.json': `${JSON.stringify(json, null, 2)}`, 'tsconfig.json': `${JSON.stringify(tsconfigJSON, null, 2)}`, 'package.json': `${JSON.stringify(packageJson, null, 2)}`, @@ -181,7 +190,7 @@ export class CodeService { ); } - openOnCodeSandbox(title: string, appComponentCode: string, includeCli: boolean = false): void { + async openOnCodeSandbox(title: string, appComponentCode: string, includeCli: boolean = false): Promise { appComponentCode = this.attachStandalone(appComponentCode); const res = this.parseCode(appComponentCode); const mockObj = this.genMock; @@ -241,7 +250,7 @@ export class CodeService { isBinary: false }, 'yarn.lock': { - content: yarnLock, + content: await this.getYarnLock(), isBinary: false } }; diff --git a/src/app/core/code/files/yarn.lock.ts b/src/assets/yarn.lock.txt similarity index 99% rename from src/app/core/code/files/yarn.lock.ts rename to src/assets/yarn.lock.txt index 5d0846e6c..bb90fab0c 100644 --- a/src/app/core/code/files/yarn.lock.ts +++ b/src/assets/yarn.lock.txt @@ -1,4 +1,4 @@ -export default `# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 @@ -8043,4 +8043,3 @@ zrender@5.4.4: integrity sha512-0VxCNJ7AGOMCWeHVyTrGzUgrK4asT4ml9PEkeGirAkKNYXYzoPJCLvmyfdoOXcjTHPs10OZVMfD1Rwg16AZyYw== dependencies: tslib "2.3.0" -`; diff --git a/src/index.html b/src/index.html index 8b7a4a0af..a2ca1933b 100644 --- a/src/index.html +++ b/src/index.html @@ -14,6 +14,7 @@ +