Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/silent-ears-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@atlaspack/feature-flags': patch
'@atlaspack/core': patch
---

Clean-up patch project paths feature-flag
17 changes: 3 additions & 14 deletions packages/core/core/src/projectPath.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
24 changes: 18 additions & 6 deletions packages/core/core/test/TargetRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -1263,7 +1275,7 @@ describe('TargetResolver', () => {
[
{
name: 'default',
distDir: serveDistDir,
distDir: relativePath(DEFAULT_OPTIONS.projectRoot, serveDistDir),
publicUrl: '/',
env: {
id: '858b9b5a5dca37d4',
Expand Down
1 change: 0 additions & 1 deletion packages/core/feature-flags/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions packages/core/feature-flags/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 11 additions & 3 deletions packages/core/test-utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
Loading