Skip to content

Commit

Permalink
Mz/bundle core n templates (#5705)
Browse files Browse the repository at this point in the history
* feat: bundle sfdx-core in core extension and lighten templates

* chore: update lock file

* chore: copy transformStream

* chore: update esbuild config for core

* feat: transition back to templates

* chore: use templates instead

* chore: bump templates to 61.4.1

* chore: bundle templates

* chore: add salesforceApiVersion for bundling

* chore: update reference

* chore: use fs rather than fs-extra

* chore: consume bundleable templates

* chore: remove apiV
  • Loading branch information
mingxuanzhangsfdx authored Aug 15, 2024
1 parent 7d5da12 commit 40b0ad4
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 59 deletions.
20 changes: 9 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 31 additions & 20 deletions packages/salesforcedx-vscode-core/esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const { build } = require('esbuild');
// const fs = require('fs').promises;
const esbuildPluginPino = require('esbuild-plugin-pino');
const fs = require('fs');

const sharedConfig = {
bundle: true,
Expand All @@ -15,35 +16,45 @@ const sharedConfig = {
external: [
'vscode',
'applicationinsights',
'shelljs',
'@salesforce/core-bundle',
'@salesforce/templates-bundle'
'shelljs'
],
minify: true
minify: true,
keepNames: true,
plugins: [
esbuildPluginPino({ transports: ['pino-pretty'] })
]
};

const copyFiles = (src, dest) => {
const stats = fs.statSync(src);
try {
if (stats.isDirectory()) {
fs.cpSync(src, dest, { recursive: true });
} else {
fs.cpSync(src, dest);
}
console.log(`Copied from ${src} to ${dest}`);
} catch (error) {
console.error('An error occurred:', error);
}
};

// copy core-bundle/lib/transformStream.js to dist if core-bundle is included
// const copyFiles = async (src, dest) => {
// try {
// // Copy the file
// await fs.copyFile(src, dest);
// console.log(`File was copied from ${src} to ${dest}`);
// } catch (error) {
// console.error('An error occurred:', error);
// }
// };
const srcPathTransformStream = '../../node_modules/@salesforce/core-bundle/lib/transformStream.js';
const destPathTransformStream = './dist/src/transformStream.js';

// const srcPath = '../../node_modules/@salesforce/core-bundle/lib/transformStream.js';
// const destPath = './dist/transformStream.js';
const srcTemplatesPath = '../../node_modules/@salesforce/templates/lib/templates';
const destTemplatesPath = './dist/templates';

(async () => {
await build({
...sharedConfig,
entryPoints: ['./src/index.ts'],
outfile: 'dist/index.js'
outdir: 'dist/src'
});
})()
.then(async () => {
// await copyFiles(srcPath, destPath);
.then(() => {
copyFiles(srcPathTransformStream, destPathTransformStream);
copyFiles(srcTemplatesPath, destTemplatesPath);
})
.catch(() => process.exit(1));
.catch(() => process.exit(1));
7 changes: 3 additions & 4 deletions packages/salesforcedx-vscode-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@salesforce/salesforcedx-utils-vscode": "61.9.0",
"@salesforce/schemas": "1.9.0",
"@salesforce/source-deploy-retrieve-bundle": "12.1.5",
"@salesforce/templates-bundle": "61.3.0",
"@salesforce/templates": "61.4.3",
"@salesforce/ts-types": "2.0.10",
"@salesforce/vscode-service-provider": "1.0.4",
"adm-zip": "0.5.10",
Expand Down Expand Up @@ -96,11 +96,10 @@
"dist"
],
"packageUpdates": {
"main": "dist/index.js",
"main": "dist/src/index.js",
"dependencies": {
"applicationinsights": "1.0.7",
"shelljs": "0.8.5",
"@salesforce/templates-bundle": "61.3.0"
"shelljs": "0.8.5"
},
"devDependencies": {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ParametersGatherer,
PostconditionChecker
} from '@salesforce/salesforcedx-utils-vscode';
import { ProjectOptions, TemplateType } from '@salesforce/templates-bundle';
import { ProjectOptions, TemplateType } from '@salesforce/templates';
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -100,8 +100,7 @@ export type ProjectTemplate = {
};

export class SelectProjectTemplate
implements ParametersGatherer<ProjectTemplate>
{
implements ParametersGatherer<ProjectTemplate> {
private readonly prefillValueProvider?: () => string;

constructor(prefillValueProvider?: () => string) {
Expand Down Expand Up @@ -187,8 +186,7 @@ export class SelectProjectFolder implements ParametersGatherer<ProjectURI> {
}

export class PathExistsChecker
implements PostconditionChecker<ProjectNameAndPathAndTemplate>
{
implements PostconditionChecker<ProjectNameAndPathAndTemplate> {
public async check(
inputs: ContinueResponse<ProjectNameAndPathAndTemplate> | CancelResponse
): Promise<ContinueResponse<ProjectNameAndPathAndTemplate> | CancelResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ContinueResponse,
ParametersGatherer
} from '@salesforce/salesforcedx-utils-vscode';
import { CreateUtil } from '@salesforce/templates-bundle';
import { CreateUtil } from '@salesforce/templates';
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
DirFileNameSelection,
ParametersGatherer
} from '@salesforce/salesforcedx-utils-vscode';
import { AnalyticsTemplateOptions, TemplateType } from '@salesforce/templates-bundle';
import { AnalyticsTemplateOptions, TemplateType } from '@salesforce/templates';
import * as vscode from 'vscode';
import { nls } from '../../messages';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { DirFileNameSelection } from '@salesforce/salesforcedx-utils-vscode';
import { ApexClassOptions, TemplateType } from '@salesforce/templates-bundle';
import { ApexClassOptions, TemplateType } from '@salesforce/templates';
import { nls } from '../../../messages';
import { LibraryBaseTemplateCommand } from '../libraryBaseTemplateCommand';
import { APEX_CLASS_TYPE } from '../metadataTypeConstants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { DirFileNameSelection } from '@salesforce/salesforcedx-utils-vscode';
import { ApexTriggerOptions, TemplateType } from '@salesforce/templates-bundle';
import { ApexTriggerOptions, TemplateType } from '@salesforce/templates';
import { nls } from '../../../messages';
import { LibraryBaseTemplateCommand } from '../libraryBaseTemplateCommand';
import { APEX_TRIGGER_TYPE } from '../metadataTypeConstants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { DirFileNameSelection } from '@salesforce/salesforcedx-utils-vscode';
import { ApexClassOptions, TemplateType } from '@salesforce/templates-bundle';
import { ApexClassOptions, TemplateType } from '@salesforce/templates';
import { nls } from '../../../messages';
import { LibraryBaseTemplateCommand } from '../libraryBaseTemplateCommand';
import { APEX_CLASS_TYPE } from '../metadataTypeConstants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TemplateOptions,
TemplateService,
TemplateType
} from '@salesforce/templates-bundle';
} from '@salesforce/templates';
import * as path from 'path';
import { ProgressLocation, window, workspace } from 'vscode';
import { channelService } from '../../channels';
Expand All @@ -35,8 +35,7 @@ type ExecutionResult = {
* Base class for all template commands
*/
export abstract class LibraryBaseTemplateCommand<T>
implements CommandletExecutor<T>
{
implements CommandletExecutor<T> {
private _metadataType: MetadataInfo | undefined;
protected showChannelOutput = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DirFileNameSelection,
LocalComponent
} from '@salesforce/salesforcedx-utils-vscode';
import { LightningAppOptions, TemplateType } from '@salesforce/templates-bundle';
import { LightningAppOptions, TemplateType } from '@salesforce/templates';
import { Uri } from 'vscode';
import { nls } from '../../messages';
import { salesforceCoreSettings } from '../../settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DirFileNameSelection,
LocalComponent
} from '@salesforce/salesforcedx-utils-vscode';
import { LightningComponentOptions, TemplateType } from '@salesforce/templates-bundle';
import { LightningComponentOptions, TemplateType } from '@salesforce/templates';
import { Uri } from 'vscode';
import { nls } from '../../messages';
import { salesforceCoreSettings } from '../../settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DirFileNameSelection,
LocalComponent
} from '@salesforce/salesforcedx-utils-vscode';
import { LightningEventOptions, TemplateType } from '@salesforce/templates-bundle';
import { LightningEventOptions, TemplateType } from '@salesforce/templates';
import { Uri } from 'vscode';
import { nls } from '../../messages';
import { salesforceCoreSettings } from '../../settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DirFileNameSelection,
LocalComponent
} from '@salesforce/salesforcedx-utils-vscode';
import { LightningInterfaceOptions, TemplateType } from '@salesforce/templates-bundle';
import { LightningInterfaceOptions, TemplateType } from '@salesforce/templates';
import { Uri } from 'vscode';
import { nls } from '../../messages';
import { salesforceCoreSettings } from '../../settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DirFileNameSelection,
LocalComponent
} from '@salesforce/salesforcedx-utils-vscode';
import { LightningComponentOptions, TemplateType } from '@salesforce/templates-bundle';
import { LightningComponentOptions, TemplateType } from '@salesforce/templates';
import { Uri } from 'vscode';
import { nls } from '../../messages';
import { salesforceCoreSettings } from '../../settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {
TemplateType,
VisualforceComponentOptions
} from '@salesforce/templates-bundle';
} from '@salesforce/templates';
import { nls } from '../../messages';
import {
CompositeParametersGatherer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DirFileNameSelection,
LocalComponent
} from '@salesforce/salesforcedx-utils-vscode';
import { TemplateType, VisualforcePageOptions } from '@salesforce/templates-bundle';
import { TemplateType, VisualforcePageOptions } from '@salesforce/templates';
import { nls } from '../../messages';
import {
CompositeParametersGatherer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { CreateUtil } from '@salesforce/templates-bundle';
import { CreateUtil } from '@salesforce/templates';
import * as fs from 'fs';
import * as path from 'path';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { TemplateType } from '@salesforce/templates-bundle';
import { TemplateType } from '@salesforce/templates';
import {
CREATE_UNIT_NAME_KEY,
LibraryApexGenerateUnitTestClassExecutor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ConfigUtil } from '@salesforce/salesforcedx-utils-vscode';
import { nls as templatesNls } from '@salesforce/templates-bundle/lib/i18n';
import { nls as templatesNls } from '@salesforce/templates/lib/i18n';
import * as path from 'path';
import * as shell from 'shelljs';
import * as sinon from 'sinon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ConfigUtil } from '@salesforce/salesforcedx-utils-vscode';
import { nls as templatesNls } from '@salesforce/templates-bundle/lib/i18n';
import { nls as templatesNls } from '@salesforce/templates/lib/i18n';
import * as path from 'path';
import * as shell from 'shelljs';
import * as sinon from 'sinon';
Expand Down

0 comments on commit 40b0ad4

Please sign in to comment.