MCPcopy
hub / github.com/rollup/rollup / loadTranspiledConfigFile

Function loadTranspiledConfigFile

cli/run/loadConfigFile.ts:105–170  ·  view source on GitHub ↗
(
	fileName: string,
	commandOptions: Record<string, unknown>
)

Source from the content-addressed store, hash-verified

103}
104
105async function loadTranspiledConfigFile(
106 fileName: string,
107 commandOptions: Record<string, unknown>
108): Promise<unknown> {
109 const { bundleConfigAsCjs, configPlugin, configImportAttributesKey, silent } = commandOptions;
110 const warnings = batchWarnings(commandOptions);
111 const inputOptions: InputOptionsWithPlugins = {
112 // Do *not* specify external callback here - instead, perform the externality check it via fallback-plugin just below this comment.
113 // This allows config plugin to first decide whether some import is external or not, and only then trigger the check in fallback-plugin.
114 // Since the check is ultra-simple during this stage of transforming the config file itself, it should be fallback instead of primary check.
115 // That way, e.g. importing workspace packages will work as expected - the workspace package will be bundled.
116 input: fileName,
117 onwarn: warnings.add,
118 plugins: [],
119 treeshake: false
120 };
121 await addPluginsFromCommandOption(configPlugin, inputOptions);
122 // Add plugin as *last* item after addPluginsFromCommandOption is complete.
123 // This plugin will trigger for imports not resolved by config plugin, and mark all non-relative imports as external.
124 inputOptions.plugins.push({
125 name: 'external-fallback',
126 resolveId: source => {
127 const looksLikeExternal =
128 (source[0] !== '.' && !path.isAbsolute(source)) || source.slice(-5) === '.json';
129 return looksLikeExternal ? false : null;
130 }
131 });
132 const bundle = await rollup.rollup(inputOptions);
133 const {
134 output: [{ code }]
135 } = await bundle.generate({
136 exports: 'named',
137 format: bundleConfigAsCjs ? 'cjs' : 'es',
138 importAttributesKey: getConfigImportAttributesKey(configImportAttributesKey),
139 plugins: [
140 {
141 name: 'transpile-import-meta',
142 resolveImportMeta(property, { moduleId }) {
143 if (property === 'url') {
144 return `'${pathToFileURL(moduleId).href}'`;
145 }
146 if (property == 'filename') {
147 return `'${moduleId}'`;
148 }
149 if (property == 'dirname') {
150 return `'${path.dirname(moduleId)}'`;
151 }
152 if (property == null) {
153 return `{url:'${pathToFileURL(moduleId).href}', filename: '${moduleId}', dirname: '${path.dirname(moduleId)}'}`;
154 }
155 }
156 }
157 ]
158 });
159 if (!silent && warnings.count > 0) {
160 stderr(bold(`loaded ${relativeId(fileName)} with warnings`));
161 warnings.flush();
162 }

Callers 1

getConfigFileExportFunction · 0.85

Calls 8

stderrFunction · 0.90
batchWarningsFunction · 0.85
relativeIdFunction · 0.85
pushMethod · 0.80
generateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…