#3883 feat: bundle closing

Merged intrnl
Coverage Reach
src/ast/nodes/shared/Node.ts src/ast/nodes/shared/FunctionNode.ts src/ast/nodes/shared/knownGlobals.ts src/ast/nodes/shared/MultiExpression.ts src/ast/nodes/shared/ClassNode.ts src/ast/nodes/ObjectExpression.ts src/ast/nodes/MemberExpression.ts src/ast/nodes/CallExpression.ts src/ast/nodes/VariableDeclaration.ts src/ast/nodes/IfStatement.ts src/ast/nodes/ConditionalExpression.ts src/ast/nodes/LogicalExpression.ts src/ast/nodes/MetaProperty.ts src/ast/nodes/ImportExpression.ts src/ast/nodes/Identifier.ts src/ast/nodes/Property.ts src/ast/nodes/ExportDefaultDeclaration.ts src/ast/nodes/SwitchStatement.ts src/ast/nodes/BinaryExpression.ts src/ast/nodes/ArrowFunctionExpression.ts src/ast/nodes/SequenceExpression.ts src/ast/nodes/AssignmentExpression.ts src/ast/nodes/ForInStatement.ts src/ast/nodes/UpdateExpression.ts src/ast/nodes/BlockStatement.ts src/ast/nodes/TryStatement.ts src/ast/nodes/ForStatement.ts src/ast/nodes/UnaryExpression.ts src/ast/nodes/LabeledStatement.ts src/ast/nodes/Literal.ts src/ast/nodes/SwitchCase.ts src/ast/nodes/ForOfStatement.ts src/ast/nodes/ArrayPattern.ts src/ast/nodes/ObjectPattern.ts src/ast/nodes/DoWhileStatement.ts src/ast/nodes/ReturnStatement.ts src/ast/nodes/WhileStatement.ts src/ast/nodes/Program.ts src/ast/nodes/ContinueStatement.ts src/ast/nodes/NewExpression.ts src/ast/nodes/BreakStatement.ts src/ast/nodes/NodeType.ts src/ast/nodes/TaggedTemplateExpression.ts src/ast/nodes/ClassDeclaration.ts src/ast/nodes/AwaitExpression.ts src/ast/nodes/AssignmentPattern.ts src/ast/nodes/ThisExpression.ts src/ast/nodes/ExportNamedDeclaration.ts src/ast/nodes/ArrayExpression.ts src/ast/nodes/RestElement.ts src/ast/nodes/YieldExpression.ts src/ast/nodes/ClassBody.ts src/ast/nodes/ExpressionStatement.ts src/ast/nodes/ThrowStatement.ts src/ast/nodes/FunctionDeclaration.ts src/ast/nodes/CatchClause.ts src/ast/nodes/TemplateLiteral.ts src/ast/nodes/ImportDeclaration.ts src/ast/nodes/TemplateElement.ts src/ast/nodes/ExportAllDeclaration.ts src/ast/nodes/MethodDefinition.ts src/ast/nodes/VariableDeclarator.ts src/ast/nodes/UnknownNode.ts src/ast/nodes/SpreadElement.ts src/ast/nodes/FieldDefinition.ts src/ast/nodes/index.ts src/ast/nodes/EmptyStatement.ts src/ast/variables/LocalVariable.ts src/ast/variables/NamespaceVariable.ts src/ast/variables/ExportDefaultVariable.ts src/ast/variables/Variable.ts src/ast/variables/SyntheticNamedExportVariable.ts src/ast/variables/ExternalVariable.ts src/ast/variables/ThisVariable.ts src/ast/variables/ArgumentsVariable.ts src/ast/variables/GlobalVariable.ts src/ast/variables/ExportShimVariable.ts src/ast/variables/UndefinedVariable.ts src/ast/scopes/ChildScope.ts src/ast/scopes/ParameterScope.ts src/ast/scopes/ModuleScope.ts src/ast/scopes/Scope.ts src/ast/scopes/ReturnValueScope.ts src/ast/scopes/FunctionScope.ts src/ast/scopes/GlobalScope.ts src/ast/scopes/TrackingScope.ts src/ast/scopes/BlockScope.ts src/ast/scopes/CatchScope.ts src/ast/scopes/ClassBodyScope.ts src/ast/values.ts src/ast/utils/PathTracker.ts src/ast/ExecutionContext.ts src/ast/keys.ts src/ast/CallOptions.ts src/utils/options/normalizeOutputOptions.ts src/utils/options/normalizeInputOptions.ts src/utils/options/mergeOptions.ts src/utils/options/options.ts src/utils/FileEmitter.ts src/utils/PluginDriver.ts src/utils/collapseSourcemaps.ts src/utils/error.ts src/utils/chunkAssignment.ts src/utils/timers.ts src/utils/renderHelpers.ts src/utils/deconflictChunk.ts src/utils/transform.ts src/utils/PluginContext.ts src/utils/executionOrder.ts src/utils/interopHelpers.ts src/utils/PluginCache.ts src/utils/pureComments.ts src/utils/getCodeFrame.ts src/utils/exportNames.ts src/utils/resolveId.ts src/utils/pluginUtils.ts src/utils/getExportMode.ts src/utils/fs.ts src/utils/getOriginalLocation.ts src/utils/renderNamePattern.ts src/utils/getIndentString.ts src/utils/systemJsRendering.ts src/utils/treeshakeNode.ts src/utils/identifierHelpers.ts src/utils/traverseStaticDependencies.ts src/utils/addons.ts src/utils/renderChunk.ts src/utils/decodedSourcemap.ts src/utils/base64.ts src/utils/commondir.ts src/utils/relativeId.ts src/utils/path.ts src/utils/getOrCreate.ts src/utils/safeName.ts src/utils/escapeId.ts src/utils/ensureArray.ts src/utils/buildPhase.ts src/utils/blank.ts src/utils/sourceMappingURL.ts src/utils/crypto.ts src/utils/sanitizeFileName.ts src/utils/reservedNames.ts src/utils/getId.ts src/utils/variableNames.ts src/Chunk.ts src/finalisers/shared/getExportBlock.ts src/finalisers/shared/getInteropBlock.ts src/finalisers/shared/setupNamespace.ts src/finalisers/shared/warnOnBuiltins.ts src/finalisers/shared/trimEmptyImports.ts src/finalisers/shared/getCompleteAmdId.ts src/finalisers/shared/sanitize.ts src/finalisers/shared/removeExtensionFromRelativeAmdId.ts src/finalisers/shared/removeJsExtension.ts src/finalisers/system.ts src/finalisers/es.ts src/finalisers/umd.ts src/finalisers/iife.ts src/finalisers/cjs.ts src/finalisers/amd.ts src/finalisers/index.ts src/Module.ts src/ModuleLoader.ts src/watch/watch.ts src/watch/fileWatcher.ts src/watch/watch-proxy.ts src/watch/fsevents-importer.ts src/Bundle.ts src/Graph.ts src/rollup/rollup.ts src/ExternalModule.ts cli/run/batchWarnings.ts cli/run/watch-cli.ts cli/run/index.ts cli/run/loadConfigFile.ts cli/run/commandPlugins.ts cli/run/build.ts cli/run/getConfigPath.ts cli/run/stdin.ts cli/run/waitForInput.ts cli/run/resetScreen.ts cli/run/loadConfigFromCommand.ts cli/run/timings.ts cli/logging.ts cli/cli.ts cli/sourceMappingUrl.ts browser/path.ts

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -62,6 +62,7 @@
Loading
62 62
	}
63 63
64 64
	await Promise.all(outputOptions.map(bundle.write));
65 +
	await bundle.close();
65 66
	if (!silent) {
66 67
		warnings.flush();
67 68
		stderr(green(`created ${bold(files.join(', '))} in ${bold(ms(Date.now() - start))}`));

@@ -2,7 +2,7 @@
Loading
2 2
import Bundle from '../Bundle';
3 3
import Graph from '../Graph';
4 4
import { ensureArray } from '../utils/ensureArray';
5 -
import { errCannotEmitFromOptionsHook, error } from '../utils/error';
5 +
import { errAlreadyClosed, errCannotEmitFromOptionsHook, error } from '../utils/error';
6 6
import { writeFile } from '../utils/fs';
7 7
import { normalizeInputOptions } from '../utils/options/normalizeInputOptions';
8 8
import { normalizeOutputOptions } from '../utils/options/normalizeOutputOptions';
@@ -56,6 +56,7 @@
Loading
56 56
			err.watchFiles = watchFiles;
57 57
		}
58 58
		await graph.pluginDriver.hookParallel('buildEnd', [err]);
59 +
		await graph.pluginDriver.hookParallel('closeBundle', []);
59 60
		throw err;
60 61
	}
61 62
@@ -65,7 +66,17 @@
Loading
65 66
66 67
	const result: RollupBuild = {
67 68
		cache: useCache ? graph.getCache() : undefined,
69 +
		closed: false,
70 +
		async close() {
71 +
			if (result.closed) return;
72 +
73 +
			result.closed = true;
74 +
75 +
			await graph.pluginDriver.hookParallel('closeBundle', []);
76 +
		},
68 77
		async generate(rawOutputOptions: OutputOptions) {
78 +
			if (result.closed) return error(errAlreadyClosed());
79 +
69 80
			return handleGenerateWrite(
70 81
				false,
71 82
				inputOptions,
@@ -76,6 +87,8 @@
Loading
76 87
		},
77 88
		watchFiles: Object.keys(graph.watchFiles),
78 89
		async write(rawOutputOptions: OutputOptions) {
90 +
			if (result.closed) return error(errAlreadyClosed());
91 +
79 92
			return handleGenerateWrite(
80 93
				true,
81 94
				inputOptions,

@@ -129,6 +129,7 @@
Loading
129 129
					if (event.result && event.result.getTimings) {
130 130
						printTimings(event.result.getTimings());
131 131
					}
132 +
					event.result.close().catch(error => handleError(error, true));
132 133
					break;
133 134
134 135
				case 'END':

@@ -47,6 +47,7 @@
Loading
47 47
} = {
48 48
	buildEnd: 1,
49 49
	buildStart: 1,
50 +
	closeBundle: 1,
50 51
	closeWatcher: 1,
51 52
	load: 1,
52 53
	moduleParsed: 1,

@@ -37,6 +37,7 @@
Loading
37 37
}
38 38
39 39
export enum Errors {
40 +
	ALREADY_CLOSED = 'ALREADY_CLOSED',
40 41
	ASSET_NOT_FINALISED = 'ASSET_NOT_FINALISED',
41 42
	ASSET_NOT_FOUND = 'ASSET_NOT_FOUND',
42 43
	ASSET_SOURCE_ALREADY_SET = 'ASSET_SOURCE_ALREADY_SET',
@@ -45,8 +46,9 @@
Loading
45 46
	CANNOT_EMIT_FROM_OPTIONS_HOOK = 'CANNOT_EMIT_FROM_OPTIONS_HOOK',
46 47
	CHUNK_NOT_GENERATED = 'CHUNK_NOT_GENERATED',
47 48
	DEPRECATED_FEATURE = 'DEPRECATED_FEATURE',
48 -
	FILE_NOT_FOUND = 'FILE_NOT_FOUND',
49 +
	EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS',
49 50
	FILE_NAME_CONFLICT = 'FILE_NAME_CONFLICT',
51 +
	FILE_NOT_FOUND = 'FILE_NOT_FOUND',
50 52
	INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN',
51 53
	INVALID_CHUNK = 'INVALID_CHUNK',
52 54
	INVALID_EXPORT_OPTION = 'INVALID_EXPORT_OPTION',
@@ -60,12 +62,11 @@
Loading
60 62
	NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE = 'NO_TRANSFORM_MAP_OR_AST_WITHOUT_CODE',
61 63
	PLUGIN_ERROR = 'PLUGIN_ERROR',
62 64
	PREFER_NAMED_EXPORTS = 'PREFER_NAMED_EXPORTS',
65 +
	SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT',
63 66
	UNEXPECTED_NAMED_IMPORT = 'UNEXPECTED_NAMED_IMPORT',
64 67
	UNRESOLVED_ENTRY = 'UNRESOLVED_ENTRY',
65 68
	UNRESOLVED_IMPORT = 'UNRESOLVED_IMPORT',
66 -
	VALIDATION_ERROR = 'VALIDATION_ERROR',
67 -
	EXTERNAL_SYNTHETIC_EXPORTS = 'EXTERNAL_SYNTHETIC_EXPORTS',
68 -
	SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT = 'SYNTHETIC_NAMED_EXPORTS_NEED_NAMESPACE_EXPORT'
69 +
	VALIDATION_ERROR = 'VALIDATION_ERROR'
69 70
}
70 71
71 72
export function errAssetNotFinalisedForFileName(name: string) {
@@ -377,6 +378,13 @@
Loading
377 378
	};
378 379
}
379 380
381 +
export function errAlreadyClosed() {
382 +
	return {
383 +
		code: Errors.ALREADY_CLOSED,
384 +
		message: 'Bundle is already closed, no more calls to "generate" or "write" are allowed.'
385 +
	};
386 +
}
387 +
380 388
export function warnDeprecation(
381 389
	deprecation: string | RollupWarning,
382 390
	activeDeprecation: boolean,

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.

21 Commits

+4595
-360
-4235
-1
-4595
+360
+4234
Hiding 2 contexual commits
+2
+1
+1
-1
-1
+2 Files
+16
+16
+4
-3
-1
Hiding 1 contexual commits
Hiding 1 contexual commits
Hiding 2 contexual commits
+2
+4
+1
-3
Hiding 1 contexual commits
-2 Files
-8
-14
+2
+4
Pull Request Base Commit
Files Coverage
cli 0.02% 94.29%
src +<.01% 97.34%
browser/path.ts 76.92%
Project Totals (187 files) 97.08%
Loading