From fd5fb91578b679f44e2ba788f64cee4a7577e4e0 Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 02:23:57 +0000 Subject: [PATCH 01/18] flow types --- .../core/cache/test/LMDBLiteCache.test.js | 7 +++-- .../core/codeframe/test/codeframe.test.js | 1 + packages/core/core/test/Dependency.test.js | 28 +++++++++++++++++-- .../requests/AssetGraphRequestRust.test.js | 11 ++++++-- .../integration-tests/test/bundle-text.js | 8 ++++-- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/packages/core/cache/test/LMDBLiteCache.test.js b/packages/core/cache/test/LMDBLiteCache.test.js index 3eba7505f..b931f9d62 100644 --- a/packages/core/cache/test/LMDBLiteCache.test.js +++ b/packages/core/cache/test/LMDBLiteCache.test.js @@ -1,8 +1,9 @@ -import * as path from 'node:path'; +// @flow +import * as path from 'path'; import {tmpdir} from 'os'; import {LMDBLiteCache} from '../src/index'; -import {deserialize, serialize} from 'node:v8'; -import assert from 'node:assert'; +import {deserialize, serialize} from 'v8'; +import assert from 'assert'; const cacheDir = path.join(tmpdir(), 'lmdb-lite-cache-tests'); diff --git a/packages/core/codeframe/test/codeframe.test.js b/packages/core/codeframe/test/codeframe.test.js index 76e099050..e11d2f7d9 100644 --- a/packages/core/codeframe/test/codeframe.test.js +++ b/packages/core/codeframe/test/codeframe.test.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import {readFileSync} from 'fs'; import {join as joinPath} from 'path'; diff --git a/packages/core/core/test/Dependency.test.js b/packages/core/core/test/Dependency.test.js index 17a279f83..d587e0de8 100644 --- a/packages/core/core/test/Dependency.test.js +++ b/packages/core/core/test/Dependency.test.js @@ -1,6 +1,8 @@ +// @flow import expect from 'expect'; import {createDependencyId} from '../src/Dependency'; import {createEnvironment} from '../src/Environment'; +import type {ProjectPath} from '../src/projectPath'; describe('Dependency', () => { describe('createDependencyId', () => { @@ -9,11 +11,23 @@ describe('Dependency', () => { specifier: 'foo', env: createEnvironment(), specifierType: 'esm', + bundleBehavior: undefined, + packageConditions: undefined, + pipeline: undefined, + priority: undefined, + sourceAssetId: undefined, + target: undefined, }); let id2 = createDependencyId({ specifier: 'foo', env: createEnvironment(), specifierType: 'esm', + bundleBehavior: undefined, + packageConditions: undefined, + pipeline: undefined, + priority: undefined, + sourceAssetId: undefined, + target: undefined, }); expect(id1).toEqual(id2); }); @@ -25,11 +39,16 @@ describe('Dependency', () => { specifierType: 'esm', target: { name: 'test-1234', - distDir: 'dist-dir', + distDir: (('dist-dir': any): ProjectPath), env: createEnvironment(), publicUrl: 'public-url', source: '1234', }, + bundleBehavior: undefined, + packageConditions: undefined, + pipeline: undefined, + priority: undefined, + sourceAssetId: undefined, }); let id2 = createDependencyId({ specifier: 'foo', @@ -37,11 +56,16 @@ describe('Dependency', () => { specifierType: 'esm', target: { name: 'test-1234', - distDir: 'dist-dir', + distDir: (('dist-dir': any): ProjectPath), env: createEnvironment(), publicUrl: 'public-url', source: '5678', // <- this is different }, + bundleBehavior: undefined, + packageConditions: undefined, + pipeline: undefined, + priority: undefined, + sourceAssetId: undefined, }); expect(id1).not.toEqual(id2); }); diff --git a/packages/core/core/test/requests/AssetGraphRequestRust.test.js b/packages/core/core/test/requests/AssetGraphRequestRust.test.js index 17ac83863..f0466fd51 100644 --- a/packages/core/core/test/requests/AssetGraphRequestRust.test.js +++ b/packages/core/core/test/requests/AssetGraphRequestRust.test.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import {getAssetGraph} from '../../src/requests/AssetGraphRequestRust'; @@ -8,8 +9,14 @@ describe('AssetGraphRequestRust -> getAssetGraph', function () { const indexAsset = assetGraph.getNodeByContentKey('79c128d4f549c408'); const libraryDep = assetGraph.getNodeByContentKey('cfe74f65a41af1a7'); - assert(indexAsset?.type === 'asset'); - assert(libraryDep?.type === 'dependency'); + if (!indexAsset) return assert(false); + if (!libraryDep) return assert(false); + + assert(indexAsset.type === 'asset'); + assert(libraryDep.type === 'dependency'); + + if (indexAsset.type !== 'asset') return assert(false); + if (libraryDep.type !== 'dependency') return assert(false); assert.equal(indexAsset.value.filePath, '/index.ts'); assert.equal(libraryDep.value.specifier, './library'); diff --git a/packages/core/integration-tests/test/bundle-text.js b/packages/core/integration-tests/test/bundle-text.js index 71a101d90..822879def 100644 --- a/packages/core/integration-tests/test/bundle-text.js +++ b/packages/core/integration-tests/test/bundle-text.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import {join} from 'path'; import { @@ -10,6 +11,7 @@ import { removeDistDirectory, run, } from '@atlaspack/test-utils'; +import type {InitialAtlaspackOptions} from '@atlaspack/types'; describe('bundle-text:', function () { beforeEach(async () => { @@ -164,7 +166,7 @@ describe('bundle-text:', function () { describe(`when scope hoisting is ${ scopeHoist ? 'enabled' : 'disabled' }`, () => { - let options = scopeHoist + let options: InitialAtlaspackOptions = scopeHoist ? { defaultTargetOptions: { isLibrary: true, @@ -172,7 +174,7 @@ describe('bundle-text:', function () { shouldScopeHoist: true, }, } - : {}; + : Object.freeze({}); it('can be used with an import that points to the same asset', async function () { await fsFixture(overlayFS, __dirname)` @@ -201,7 +203,7 @@ describe('bundle-text:', function () { assets: [ 'index.js', 'main.js', - !scopeHoist && 'esmodule-helpers.js', + ...(!scopeHoist ? ['esmodule-helpers.js'] : []), ].filter(Boolean), }, { From 1371e5b7f731a0d57b8e0923ebd3b43509fb2252 Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 02:38:09 +0000 Subject: [PATCH 02/18] Changing the underlying type rather than the caller --- packages/core/core/src/Dependency.js | 12 ++++++------ packages/core/core/test/Dependency.test.js | 22 ---------------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/packages/core/core/src/Dependency.js b/packages/core/core/src/Dependency.js index 098f2bd6d..7650efadb 100644 --- a/packages/core/core/src/Dependency.js +++ b/packages/core/core/src/Dependency.js @@ -57,15 +57,15 @@ export function createDependencyId({ priority, packageConditions, }: {| - sourceAssetId: string | void, + sourceAssetId?: string | void, specifier: DependencySpecifier, env: Environment, - target: Target | void, - pipeline: ?string, + target?: Target | void, + pipeline?: ?string, specifierType: $Keys, - bundleBehavior: ?IBundleBehavior, - priority: $Keys | void, - packageConditions: Array | void, + bundleBehavior?: ?IBundleBehavior, + priority?: $Keys | void, + packageConditions?: Array | void, |}): string { assert(typeof specifierType === 'string'); assert(typeof priority === 'string' || priority == null); diff --git a/packages/core/core/test/Dependency.test.js b/packages/core/core/test/Dependency.test.js index d587e0de8..ec3d899d5 100644 --- a/packages/core/core/test/Dependency.test.js +++ b/packages/core/core/test/Dependency.test.js @@ -11,23 +11,11 @@ describe('Dependency', () => { specifier: 'foo', env: createEnvironment(), specifierType: 'esm', - bundleBehavior: undefined, - packageConditions: undefined, - pipeline: undefined, - priority: undefined, - sourceAssetId: undefined, - target: undefined, }); let id2 = createDependencyId({ specifier: 'foo', env: createEnvironment(), specifierType: 'esm', - bundleBehavior: undefined, - packageConditions: undefined, - pipeline: undefined, - priority: undefined, - sourceAssetId: undefined, - target: undefined, }); expect(id1).toEqual(id2); }); @@ -44,11 +32,6 @@ describe('Dependency', () => { publicUrl: 'public-url', source: '1234', }, - bundleBehavior: undefined, - packageConditions: undefined, - pipeline: undefined, - priority: undefined, - sourceAssetId: undefined, }); let id2 = createDependencyId({ specifier: 'foo', @@ -61,11 +44,6 @@ describe('Dependency', () => { publicUrl: 'public-url', source: '5678', // <- this is different }, - bundleBehavior: undefined, - packageConditions: undefined, - pipeline: undefined, - priority: undefined, - sourceAssetId: undefined, }); expect(id1).not.toEqual(id2); }); From 80aff1819581ec30d4f61cb198e7889d8b2ea3ea Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 02:46:23 +0000 Subject: [PATCH 03/18] null checks --- .../core/test/requests/AssetGraphRequestRust.test.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/core/core/test/requests/AssetGraphRequestRust.test.js b/packages/core/core/test/requests/AssetGraphRequestRust.test.js index f0466fd51..bb8440722 100644 --- a/packages/core/core/test/requests/AssetGraphRequestRust.test.js +++ b/packages/core/core/test/requests/AssetGraphRequestRust.test.js @@ -9,14 +9,8 @@ describe('AssetGraphRequestRust -> getAssetGraph', function () { const indexAsset = assetGraph.getNodeByContentKey('79c128d4f549c408'); const libraryDep = assetGraph.getNodeByContentKey('cfe74f65a41af1a7'); - if (!indexAsset) return assert(false); - if (!libraryDep) return assert(false); - - assert(indexAsset.type === 'asset'); - assert(libraryDep.type === 'dependency'); - - if (indexAsset.type !== 'asset') return assert(false); - if (libraryDep.type !== 'dependency') return assert(false); + if (indexAsset?.type !== 'asset') return assert(false); + if (libraryDep?.type !== 'dependency') return assert(false); assert.equal(indexAsset.value.filePath, '/index.ts'); assert.equal(libraryDep.value.specifier, './library'); From cab63319697ad5cc453cd723d880370b5c7c947d Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 03:46:21 +0000 Subject: [PATCH 04/18] comments --- packages/core/integration-tests/test/bundle-text.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/integration-tests/test/bundle-text.js b/packages/core/integration-tests/test/bundle-text.js index 822879def..3ecdc52c7 100644 --- a/packages/core/integration-tests/test/bundle-text.js +++ b/packages/core/integration-tests/test/bundle-text.js @@ -204,7 +204,7 @@ describe('bundle-text:', function () { 'index.js', 'main.js', ...(!scopeHoist ? ['esmodule-helpers.js'] : []), - ].filter(Boolean), + ], }, { type: 'js', From 9c6b3d69358e1f1f3af29e352b8d9c3761881a95 Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 03:07:07 +0000 Subject: [PATCH 05/18] bundler --- packages/core/integration-tests/test/bundler.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/core/integration-tests/test/bundler.js b/packages/core/integration-tests/test/bundler.js index f60e4d05c..a234c6076 100644 --- a/packages/core/integration-tests/test/bundler.js +++ b/packages/core/integration-tests/test/bundler.js @@ -1,3 +1,4 @@ +// @flow import path from 'path'; import assert from 'assert'; import Logger from '@atlaspack/logger'; @@ -885,10 +886,16 @@ describe('bundler', function () { }, ]); + let assetBar = findAsset(b, 'bar.js'); + if (!assetBar) return assert(false); + + let assetC = findAsset(b, 'c.js'); + if (!assetC) return assert(false); + assert( b - .getReferencedBundles(b.getBundlesWithAsset(findAsset(b, 'bar.js'))[0]) - .includes(b.getBundlesWithAsset(findAsset(b, 'c.js'))[0]), + .getReferencedBundles(b.getBundlesWithAsset(assetBar)[0]) + .includes(b.getBundlesWithAsset(assetC)[0]), ); await run(b); @@ -950,6 +957,7 @@ describe('bundler', function () { .find( (bundle) => !bundle.getMainEntry() && bundle.name.includes('runtime'), ); + if (!aManifestBundle) return assert(false); let bBundles = b .getBundles() @@ -962,6 +970,8 @@ describe('bundler', function () { stop(); } }); + if (!aBundleManifestAsset) return assert(false); + let aBundleManifestAssetCode = await aBundleManifestAsset.getCode(); // Assert the a.js manifest bundle is aware of all the b.js bundles @@ -1323,6 +1333,8 @@ describe('bundler', function () { // Asset should not be inlined const index = b.getBundles().find((b) => b.name.startsWith('index')); + if (!index) return assert(false); + const contents = overlayFS.readFileSync(index.filePath, 'utf8'); assert( !contents.includes('async value'), From baf92587a929146f9c330fd2239fb0b63c2787a5 Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 03:15:28 +0000 Subject: [PATCH 06/18] Added @flow to the easy ones --- packages/core/integration-tests/test/compressors.js | 1 + packages/core/integration-tests/test/config-merging.js | 1 + packages/core/integration-tests/test/data-url.js | 1 + packages/core/integration-tests/test/encodedURI.js | 1 + packages/core/integration-tests/test/feature-flags.js | 5 +++-- packages/core/integration-tests/test/glsl.js | 1 + packages/core/integration-tests/test/graphql.js | 1 + packages/core/integration-tests/test/json.js | 1 + packages/core/integration-tests/test/json5.js | 1 + packages/core/integration-tests/test/namer.js | 1 + packages/core/integration-tests/test/packager.js | 1 + packages/core/integration-tests/test/plugin.js | 1 - packages/core/integration-tests/test/pug.js | 1 + packages/core/integration-tests/test/sass.js | 1 + packages/core/integration-tests/test/svg-react.js | 1 + packages/core/workers/test/cpuCount.test.js | 1 + packages/core/workers/test/workerfarm.js | 1 + packages/transformers/svg/test/parseFuncIRI.test.js | 1 + 18 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/core/integration-tests/test/compressors.js b/packages/core/integration-tests/test/compressors.js index 49eef2740..5d19cf423 100644 --- a/packages/core/integration-tests/test/compressors.js +++ b/packages/core/integration-tests/test/compressors.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import zlib from 'zlib'; diff --git a/packages/core/integration-tests/test/config-merging.js b/packages/core/integration-tests/test/config-merging.js index 628df1fe7..6d9170c86 100644 --- a/packages/core/integration-tests/test/config-merging.js +++ b/packages/core/integration-tests/test/config-merging.js @@ -1,3 +1,4 @@ +// @flow import {bundle, describe, it, run, outputFS} from '@atlaspack/test-utils'; import assert from 'assert'; import path from 'path'; diff --git a/packages/core/integration-tests/test/data-url.js b/packages/core/integration-tests/test/data-url.js index 6fd50b6e1..41b4113ad 100644 --- a/packages/core/integration-tests/test/data-url.js +++ b/packages/core/integration-tests/test/data-url.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import {join} from 'path'; import { diff --git a/packages/core/integration-tests/test/encodedURI.js b/packages/core/integration-tests/test/encodedURI.js index 3d39ca612..a3021619a 100644 --- a/packages/core/integration-tests/test/encodedURI.js +++ b/packages/core/integration-tests/test/encodedURI.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import {join} from 'path'; import {bundle, describe, it, outputFS, distDir} from '@atlaspack/test-utils'; diff --git a/packages/core/integration-tests/test/feature-flags.js b/packages/core/integration-tests/test/feature-flags.js index 8c448666c..794822952 100644 --- a/packages/core/integration-tests/test/feature-flags.js +++ b/packages/core/integration-tests/test/feature-flags.js @@ -1,6 +1,7 @@ +// @flow import assert from 'assert'; -import path from 'node:path'; -import {rimraf} from 'rimraf'; +import path from 'path'; +import rimraf from 'rimraf'; import { bundle, describe, diff --git a/packages/core/integration-tests/test/glsl.js b/packages/core/integration-tests/test/glsl.js index 06d9b4ba0..f785d6996 100644 --- a/packages/core/integration-tests/test/glsl.js +++ b/packages/core/integration-tests/test/glsl.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import fs from 'fs'; diff --git a/packages/core/integration-tests/test/graphql.js b/packages/core/integration-tests/test/graphql.js index 38f38275e..a21b60365 100644 --- a/packages/core/integration-tests/test/graphql.js +++ b/packages/core/integration-tests/test/graphql.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import {bundle, describe, it, run} from '@atlaspack/test-utils'; diff --git a/packages/core/integration-tests/test/json.js b/packages/core/integration-tests/test/json.js index 8003ba04e..0ec64a8c1 100644 --- a/packages/core/integration-tests/test/json.js +++ b/packages/core/integration-tests/test/json.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import {join} from 'path'; import { diff --git a/packages/core/integration-tests/test/json5.js b/packages/core/integration-tests/test/json5.js index abb202a27..21d264adb 100644 --- a/packages/core/integration-tests/test/json5.js +++ b/packages/core/integration-tests/test/json5.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import {join} from 'path'; import { diff --git a/packages/core/integration-tests/test/namer.js b/packages/core/integration-tests/test/namer.js index 223181f0f..adf7cc33e 100644 --- a/packages/core/integration-tests/test/namer.js +++ b/packages/core/integration-tests/test/namer.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import {bundle, describe, it, outputFS, distDir} from '@atlaspack/test-utils'; diff --git a/packages/core/integration-tests/test/packager.js b/packages/core/integration-tests/test/packager.js index 27b72cb74..55f2eda24 100644 --- a/packages/core/integration-tests/test/packager.js +++ b/packages/core/integration-tests/test/packager.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import nullthrows from 'nullthrows'; diff --git a/packages/core/integration-tests/test/plugin.js b/packages/core/integration-tests/test/plugin.js index 6795cf559..3dc2eae74 100644 --- a/packages/core/integration-tests/test/plugin.js +++ b/packages/core/integration-tests/test/plugin.js @@ -1,5 +1,4 @@ // @flow - import assert from 'assert'; import invariant from 'assert'; import path from 'path'; diff --git a/packages/core/integration-tests/test/pug.js b/packages/core/integration-tests/test/pug.js index ef1b577fe..6cfbea507 100644 --- a/packages/core/integration-tests/test/pug.js +++ b/packages/core/integration-tests/test/pug.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import { diff --git a/packages/core/integration-tests/test/sass.js b/packages/core/integration-tests/test/sass.js index d3cdcd151..82ef92cfb 100644 --- a/packages/core/integration-tests/test/sass.js +++ b/packages/core/integration-tests/test/sass.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import { diff --git a/packages/core/integration-tests/test/svg-react.js b/packages/core/integration-tests/test/svg-react.js index 968b42335..ebb198388 100644 --- a/packages/core/integration-tests/test/svg-react.js +++ b/packages/core/integration-tests/test/svg-react.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import {bundle, describe, it, outputFS} from '@atlaspack/test-utils'; import path from 'path'; diff --git a/packages/core/workers/test/cpuCount.test.js b/packages/core/workers/test/cpuCount.test.js index d89b2d980..d1981ebbd 100644 --- a/packages/core/workers/test/cpuCount.test.js +++ b/packages/core/workers/test/cpuCount.test.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import os from 'os'; diff --git a/packages/core/workers/test/workerfarm.js b/packages/core/workers/test/workerfarm.js index a4313f94b..2beec389e 100644 --- a/packages/core/workers/test/workerfarm.js +++ b/packages/core/workers/test/workerfarm.js @@ -1,3 +1,4 @@ +// @flow import Logger from '@atlaspack/logger'; import assert from 'assert'; import WorkerFarm from '../src'; diff --git a/packages/transformers/svg/test/parseFuncIRI.test.js b/packages/transformers/svg/test/parseFuncIRI.test.js index 546e6c072..172adce64 100644 --- a/packages/transformers/svg/test/parseFuncIRI.test.js +++ b/packages/transformers/svg/test/parseFuncIRI.test.js @@ -1,3 +1,4 @@ +// @flow import {parseFuncIRI} from '../src/dependencies'; import assert from 'assert'; From abc343cf3bcecf310273226dba9ded0d93f31192 Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 03:35:23 +0000 Subject: [PATCH 07/18] rimraf --- flow-typed/npm/rimraf_v5.x.x.js | 1 + packages/core/integration-tests/test/feature-flags.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/flow-typed/npm/rimraf_v5.x.x.js b/flow-typed/npm/rimraf_v5.x.x.js index 11ee588e0..82700b083 100644 --- a/flow-typed/npm/rimraf_v5.x.x.js +++ b/flow-typed/npm/rimraf_v5.x.x.js @@ -9,6 +9,7 @@ declare module 'rimraf' { declare module.exports: { (f: string, opts?: Options): Promise, + rimraf(f: string, opts?: Options): Promise, sync(path: string, opts?: Options): boolean, ... }; diff --git a/packages/core/integration-tests/test/feature-flags.js b/packages/core/integration-tests/test/feature-flags.js index 794822952..db9f1e9f3 100644 --- a/packages/core/integration-tests/test/feature-flags.js +++ b/packages/core/integration-tests/test/feature-flags.js @@ -1,7 +1,7 @@ // @flow import assert from 'assert'; import path from 'path'; -import rimraf from 'rimraf'; +import {rimraf} from 'rimraf'; import { bundle, describe, From f65a1b721ab5c8692a8ace0fce68d0864ea80fac Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 03:31:45 +0000 Subject: [PATCH 08/18] contentHashing --- .../integration-tests/test/contentHashing.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/core/integration-tests/test/contentHashing.js b/packages/core/integration-tests/test/contentHashing.js index b3bedd284..1ea2cc0e0 100644 --- a/packages/core/integration-tests/test/contentHashing.js +++ b/packages/core/integration-tests/test/contentHashing.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; import { @@ -99,11 +100,19 @@ describe('content hashing', function () { async () => { let a = await _bundle( path.join(__dirname, 'integration/hash-distDir/a/index.html'), - {sourceMaps: true}, + { + defaultTargetOptions: { + sourceMaps: true, + }, + }, ); let b = await _bundle( path.join(__dirname, 'integration/hash-distDir/b/index.html'), - {sourceMaps: true}, + { + defaultTargetOptions: { + sourceMaps: true, + }, + }, ); let aBundles = a.getBundles(); @@ -113,7 +122,11 @@ describe('content hashing', function () { assert.equal(bBundles.length, 2); let aJS = aBundles.find((bundle) => bundle.type === 'js'); + if (!aJS) return assert(false); + let bJS = bBundles.find((bundle) => bundle.type === 'js'); + if (!bJS) return assert(false); + assert(/index\.[a-f0-9]*\.js/.test(path.basename(aJS.filePath))); assert.equal(aJS.name, bJS.name); }, From 20655605ed108592c660c65b8339d7484c988a19 Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 03:49:34 +0000 Subject: [PATCH 09/18] globals --- packages/core/integration-tests/test/globals.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/core/integration-tests/test/globals.js b/packages/core/integration-tests/test/globals.js index 885efb0a2..f50904f2c 100644 --- a/packages/core/integration-tests/test/globals.js +++ b/packages/core/integration-tests/test/globals.js @@ -1,3 +1,4 @@ +// @flow import assert from 'assert'; import path from 'path'; @@ -58,7 +59,6 @@ describe('globals', function () { it('when scope hoisting is disabled', async function () { let bundleGraph = await bundle(path.join(dir, 'index.js'), { defaultTargetOptions: { - context: 'browser', shouldScopeHoist: false, }, inputFS: overlayFS, @@ -84,7 +84,6 @@ describe('globals', function () { it.v2('when scope hoisting is enabled', async function () { let bundleGraph = await bundle(path.join(dir, 'index.js'), { defaultTargetOptions: { - context: 'browser', shouldScopeHoist: true, }, inputFS: overlayFS, From 2662bf94b3bd2f225edce4d330200f8ba3cc9183 Mon Sep 17 00:00:00 2001 From: David Alsh Date: Thu, 12 Dec 2024 04:22:37 +0000 Subject: [PATCH 10/18] html --- flow-typed/node/assert.js | 29 +++ packages/core/integration-tests/test/html.js | 215 +++++++++++-------- packages/core/test-utils/src/utils.js | 13 +- 3 files changed, 160 insertions(+), 97 deletions(-) create mode 100644 flow-typed/node/assert.js diff --git a/flow-typed/node/assert.js b/flow-typed/node/assert.js new file mode 100644 index 000000000..cb50e80c7 --- /dev/null +++ b/flow-typed/node/assert.js @@ -0,0 +1,29 @@ +// Missing flow types for node:assert +declare module "assert/strict" { + declare module.exports: { + (value: any, message?: string): void; + ok(value: any, message?: string): void; + fail(message?: string | Error): void; + // deprecated since v10.15 + fail(actual: any, expected: any, message: string, operator: string): void; + equal(actual: any, expected: any, message?: string): void; + strictEqual(actual: any, expected: any, message?: string): void, + notEqual(actual: any, expected: any, message?: string): void; + deepEqual(actual: any, expected: any, message?: string): void; + notDeepEqual(actual: any, expected: any, message?: string): void; + throws( + block: Function, + error?: Function | RegExp | (err: any) => boolean, + message?: string + ): void; + rejects( + block: Function, + error?: Function | RegExp | (err: any) => boolean, + message?: string + ): void; + doesNotThrow(block: Function, message?: string): void; + ifError(value: any): void; + AssertionError: typeof AssertionError; + ... + } +} diff --git a/packages/core/integration-tests/test/html.js b/packages/core/integration-tests/test/html.js index 6a8ae7218..7cec59b08 100644 --- a/packages/core/integration-tests/test/html.js +++ b/packages/core/integration-tests/test/html.js @@ -1,4 +1,5 @@ -import assert from 'assert'; +// @flow +import assert from 'assert/strict'; import { assertBundles, bundle, @@ -94,6 +95,8 @@ describe('html', function () { assert(html.includes('https://unpkg.com/parcel-bundler')); let iconsBundle = b.getBundles().find((b) => b.name.startsWith('icons')); + if (!iconsBundle) return assert(false); + assert( html.includes('/' + path.basename(iconsBundle.filePath) + '#icon-code'), ); @@ -121,8 +124,8 @@ describe('html', function () { }, ]); - assert(await outputFS.exists(path.join(distDir, 'a.html'), 'utf8')); - assert(await outputFS.exists(path.join(distDir, 'b.html'), 'utf8')); + assert(await outputFS.exists(path.join(distDir, 'a.html'))); + assert(await outputFS.exists(path.join(distDir, 'b.html'))); }); it('should find href attr when not first', async function () { @@ -462,7 +465,9 @@ describe('html', function () { let b = await bundle( path.join(__dirname, '/integration/html-css-js/index.html'), { - hmr: true, + // Test is skipped, hmr does not exist on InitialOptions + // Leaving it here to fix when the test is enabled in future + // hmr: true, }, ); @@ -956,23 +961,25 @@ describe('html', function () { path.join(__dirname, '/integration/webmanifest/index.html'), ); - assertBundles(b, { - name: 'index.html', - assets: ['index.html'], - childBundles: [ - { - type: 'webmanifest', - assets: ['manifest.webmanifest'], - childBundles: [ - { - type: 'txt', - assets: ['some.txt'], - childBundles: [], - }, - ], - }, - ], - }); + assertBundles(b, [ + { + name: 'index.html', + assets: ['index.html'], + childBundles: [ + { + type: 'webmanifest', + assets: ['manifest.webmanifest'], + childBundles: [ + { + type: 'txt', + assets: ['some.txt'], + childBundles: [], + }, + ], + }, + ], + }, + ]); }); it.skip("should treat webmanifest as an entry module so it doesn't get content hashed", async function () { @@ -980,16 +987,18 @@ describe('html', function () { path.join(__dirname, '/integration/html-manifest/index.html'), ); - assertBundles(b, { - name: 'index.html', - assets: ['index.html'], - childBundles: [ - { - type: 'webmanifest', - assets: ['manifest.webmanifest'], - }, - ], - }); + assertBundles(b, [ + { + name: 'index.html', + assets: ['index.html'], + childBundles: [ + { + type: 'webmanifest', + assets: ['manifest.webmanifest'], + }, + ], + }, + ]); const html = await outputFS.readFile( path.join(__dirname, '/dist/index.html'), @@ -1210,11 +1219,10 @@ describe('html', function () { ]); let bundles = b.getBundles(); + let foundBundle = bundles.find((bundle) => bundle.type === 'html'); + if (!foundBundle) return assert(false); - let html = await outputFS.readFile( - bundles.find((bundle) => bundle.type === 'html').filePath, - 'utf8', - ); + let html = await outputFS.readFile(foundBundle.filePath, 'utf8'); let urls = [...html.matchAll(/url\(([^)]*)\)/g)].map((m) => m[1]); assert.strictEqual(urls.length, 2); @@ -1412,7 +1420,7 @@ describe('html', function () { for (let scopeHoist of [false, true]) { it.v2( 'should expose top level declarations globally in inline