Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use import rather than fs read #1359

Merged
merged 10 commits into from
Jun 28, 2024
Merged

Conversation

mingxuanzhangsfdx
Copy link
Member

What does this PR do?

the unspecified imports or file reads makes esbuild unable to bundle the modules. This PR fixes the issue that the presets json files are not bundled.

What issues does this PR fix or reference?

@W-16114122@

Functionality Before

presets json modules are not able to be bundled without specifications, and results in the failure in extensions.

Functionality After

presets json modules are able to be bundled directly.

@mingxuanzhangsfdx mingxuanzhangsfdx requested a review from a team as a code owner June 28, 2024 00:22
import { Logger, SfProject, SfProjectJson, Lifecycle } from '@salesforce/core';
import { deepFreeze } from '../utils/collections';
import { MetadataRegistry } from './types';
import * as registryData from './metadataRegistry.json';
import decomposeCustomLabelsBeta from './presets/decomposeCustomLabelsBeta.json';
Copy link
Member Author

@mingxuanzhangsfdx mingxuanzhangsfdx Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not use asynchronous imports for the presets jsons. Making the imports async will result in making all outer functions async.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldn't you use the import * as and as MetadataRegistry pattern that works for metadataRegistry.json to make a Map<string, MetadataRegistry>

turning the json into a string and then turning it back into json seems odd...is that something necessary for the bundling to work? Why is it not necessary for metadataRegistry.json

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to compare the content

import * as path from 'node:path';
import * as fs from 'node:fs';
const pathToCheck = path.join(__dirname, 'presets', 'decomposeCustomLabelsBeta.json');
console.log(fs.readFileSync(pathToCheck, 'utf-8'))
import * as decomposeCustomLabelsBeta from './presets/decomposeCustomLabelsBeta.json';
console.log(JSON.stringify(decomposeCustomLabelsBeta));

And noticed the output of JSON.stringify(decomposeCustomLabelsBeta) is not what I want.

There is a dummy default field there, which makes it different from the output of fs.readFileSync(pathToCheck, 'utf-8')

{"childTypes":{"customlabel":"customlabels"},"suffixes":{"label":"customlabel"},"strictDirectoryNames":{"labels":"customlabels"},"types":{"customlabels":{"children":{"suffixes":{"label":"customlabel"},"types":{"customlabel":{"directoryName":"test","id":"customlabel","name":"CustomLabel","suffix":"label","isAddressable":false,"supportsWildcardAndName":true,"uniqueIdElement":"fullName","xmlElementName":"labels"}}},"strictDirectoryName":true,"directoryName":"labels","id":"customlabels","ignoreParsedFullName":false,"name":"CustomLabels","strategies":{"adapter":"decomposed","decomposition":"topLevel","transformer":"decomposed"},"suffix":"labels","supportsPartialDelete":true}},"default":{"childTypes":{"customlabel":"customlabels"},"suffixes":{"label":"customlabel"},"strictDirectoryNames":{"labels":"customlabels"},"types":{"customlabels":{"children":{"suffixes":{"label":"customlabel"},"types":{"customlabel":{"directoryName":"test","id":"customlabel","name":"CustomLabel","suffix":"label","isAddressable":false,"supportsWildcardAndName":true,"uniqueIdElement":"fullName","xmlElementName":"labels"}}},"strictDirectoryName":true,"directoryName":"labels","id":"customlabels","ignoreParsedFullName":false,"name":"CustomLabels","strategies":{"adapter":"decomposed","decomposition":"topLevel","transformer":"decomposed"},"suffix":"labels","supportsPartialDelete":true}}}}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's an artifact of import/export (like export default foo it's there for you in case you're importing it not using the *)

src/registry/variants.ts Outdated Show resolved Hide resolved
@mshanemc mshanemc merged commit db46af6 into main Jun 28, 2024
71 checks passed
@mshanemc mshanemc deleted the mz/refactor-unspecified-import branch June 28, 2024 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants