diff --git a/.changeset/silent-ears-wonder.md b/.changeset/silent-ears-wonder.md new file mode 100644 index 0000000000..6aee510813 --- /dev/null +++ b/.changeset/silent-ears-wonder.md @@ -0,0 +1,6 @@ +--- +'@atlaspack/feature-flags': patch +'@atlaspack/core': patch +--- + +Clean-up patch project paths feature-flag diff --git a/packages/core/core/src/projectPath.js b/packages/core/core/src/projectPath.js index cc3e701786..eb8a168c9b 100644 --- a/packages/core/core/src/projectPath.js +++ b/packages/core/core/src/projectPath.js @@ -1,8 +1,7 @@ // @flow strict-local import type {FilePath} from '@atlaspack/types'; import path from 'path'; -import {relativePath, normalizeSeparators} from '@atlaspack/utils'; -import {getFeatureFlagValue} from '@atlaspack/feature-flags'; +import {relativePath} from '@atlaspack/utils'; /** * A path that's relative to the project root. @@ -30,19 +29,9 @@ function toProjectPath_(projectRoot: FilePath, p: FilePath): ProjectPath { return p; } - // If the file is outside the project root, store an absolute path rather than a relative one. - // This way if the project root is moved, the file references still work. Accessing files outside - // the project root is not portable anyway. + // If the file is outside the project root, we store a relative path. + // Relative paths make the cache portable across machines. let relative = relativePath(projectRoot, p, false); - if (relative.startsWith('..')) { - // e.g given projectRoot = '/Users/monorepo/project' and p = '/Users/monorepo/other-project/src/index.js' --> relative = '../other-project/src/index.js' - if (getFeatureFlagValue('patchProjectPaths')) { - return relative; - } - - return process.platform === 'win32' ? normalizeSeparators(p) : p; - } - return relative; } diff --git a/packages/core/core/test/TargetRequest.test.js b/packages/core/core/test/TargetRequest.test.js index 8881fe8092..2b9f6cfb8f 100644 --- a/packages/core/core/test/TargetRequest.test.js +++ b/packages/core/core/test/TargetRequest.test.js @@ -5,7 +5,7 @@ import path from 'path'; import tempy from 'tempy'; import {inputFS as fs} from '@atlaspack/test-utils'; import {md} from '@atlaspack/diagnostic'; -import {normalizeSeparators} from '@atlaspack/utils'; +import {relativePath} from '@atlaspack/utils'; import {TargetResolver} from '../src/requests/TargetRequest'; import {DEFAULT_OPTIONS as _DEFAULT_OPTIONS, relative} from './test-utils'; @@ -123,7 +123,10 @@ describe('TargetResolver', () => { { name: 'customA', publicUrl: '/', - distDir: normalizeSeparators(path.resolve('customA')), + distDir: relativePath( + DEFAULT_OPTIONS.projectRoot, + path.resolve('customA'), + ), env: { id: 'd821e85f6b50315e', context: 'browser', @@ -145,7 +148,10 @@ describe('TargetResolver', () => { name: 'customB', publicUrl: '/', distEntry: 'b.js', - distDir: normalizeSeparators(path.resolve('customB')), + distDir: relativePath( + DEFAULT_OPTIONS.projectRoot, + path.resolve('customB'), + ), env: { id: 'e45cc12216f7857d', context: 'node', @@ -631,7 +637,10 @@ describe('TargetResolver', () => { [ { name: 'customB', - distDir: normalizeSeparators(path.resolve('customB')), + distDir: relativePath( + DEFAULT_OPTIONS.projectRoot, + path.resolve('customB'), + ), publicUrl: '/', env: { id: 'd821e85f6b50315e', @@ -674,7 +683,10 @@ describe('TargetResolver', () => { [ { name: 'customA', - distDir: normalizeSeparators(path.resolve('customA')), + distDir: relativePath( + DEFAULT_OPTIONS.projectRoot, + path.resolve('customA'), + ), publicUrl: '/', env: { id: 'd821e85f6b50315e', @@ -1263,7 +1275,7 @@ describe('TargetResolver', () => { [ { name: 'default', - distDir: serveDistDir, + distDir: relativePath(DEFAULT_OPTIONS.projectRoot, serveDistDir), publicUrl: '/', env: { id: '858b9b5a5dca37d4', diff --git a/packages/core/feature-flags/src/index.js b/packages/core/feature-flags/src/index.js index f8a2bf3ce8..c2634a99ed 100644 --- a/packages/core/feature-flags/src/index.js +++ b/packages/core/feature-flags/src/index.js @@ -26,7 +26,6 @@ export const DEFAULT_FEATURE_FLAGS: FeatureFlags = { reduceResolverStringCreation: false, inlineBundlesSourceMapFixes: false, conditionalBundlingNestedRuntime: false, - patchProjectPaths: false, cachePerformanceImprovements: process.env.NODE_ENV === 'test', environmentDeduplication: false, inlineStringReplacementPerf: false, diff --git a/packages/core/feature-flags/src/types.js b/packages/core/feature-flags/src/types.js index 38215dd50b..e9d5e05527 100644 --- a/packages/core/feature-flags/src/types.js +++ b/packages/core/feature-flags/src/types.js @@ -73,10 +73,6 @@ export type FeatureFlags = {| * Enable nested loading of bundles in the runtime with conditional bundling */ conditionalBundlingNestedRuntime: boolean, - /** Enable patch project paths. This will patch the project paths to be relative to the project root. - * This feature is experimental and should not be used in production. It will used to test downloadble cache artefacts. - */ - patchProjectPaths: boolean, /** * Enables optimized inline string replacement perf for the packager. * Used heavily for inline bundles. diff --git a/packages/core/test-utils/src/utils.js b/packages/core/test-utils/src/utils.js index 433beeb731..6388dbc5b4 100644 --- a/packages/core/test-utils/src/utils.js +++ b/packages/core/test-utils/src/utils.js @@ -502,9 +502,17 @@ export async function runBundle( if (src.hostname == null) { let p = path.join(distDir, nullthrows(src.pathname)); let b = nullthrows( - bundles.find( - (b) => b.bundleBehavior !== 'inline' && b.filePath === p, - ), + bundles.find((b) => { + // This is not right. + // What is happening is that the bundle distDir is set to a relative path as of `patchProjectPaths` + // However, the bundle filePath is still set to an absolute path, just a non-resolved one. + // + // We should make sure that the bundle file-paths stored are also stored as relative to the project root + // not as absolute paths. + return ( + b.bundleBehavior !== 'inline' && path.resolve(b.filePath) === p + ); + }), ); scripts.push([overlayFS.readFileSync(b.filePath, 'utf8'), b]); }