-
Notifications
You must be signed in to change notification settings - Fork 99
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
Conversation
src/registry/variants.ts
Outdated
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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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}}}}
There was a problem hiding this comment.
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 *
)
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.