Skip to content

Commit

Permalink
Don't use deprecated querystring package (#6806)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Oct 7, 2021
1 parent a6a6fb2 commit aafc318
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 77 deletions.
1 change: 0 additions & 1 deletion packages/core/core/package.json
Expand Up @@ -47,7 +47,6 @@
"json5": "^1.0.1",
"micromatch": "^4.0.2",
"nullthrows": "^1.1.1",
"querystring": "^0.2.0",
"semver": "^5.4.1"
},
"devDependencies": {
Expand Down
6 changes: 2 additions & 4 deletions packages/core/core/src/AssetGraph.js
Expand Up @@ -19,7 +19,7 @@ import type {

import invariant from 'assert';
import {hashString, Hash} from '@parcel/hash';
import {hashObject, objectSortedEntries} from '@parcel/utils';
import {hashObject} from '@parcel/utils';
import nullthrows from 'nullthrows';
import {ContentGraph} from '@parcel/graph';
import {createDependency} from './Dependency';
Expand Down Expand Up @@ -62,9 +62,7 @@ export function nodeFromAssetGroup(assetGroup: AssetGroup): AssetGroupNode {
':' +
(assetGroup.pipeline ?? '') +
':' +
(assetGroup.query
? JSON.stringify(objectSortedEntries(assetGroup.query))
: ''),
(assetGroup.query ?? ''),
),
type: 'asset_group',
value: assetGroup,
Expand Down
23 changes: 12 additions & 11 deletions packages/core/core/src/BundleGraph.js
Expand Up @@ -7,7 +7,6 @@ import type {
TraversalActions,
} from '@parcel/types';
import type {NodeId, SerializedContentGraph} from '@parcel/graph';
import querystring from 'querystring';

import type {
Asset,
Expand Down Expand Up @@ -1491,16 +1490,18 @@ export default class BundleGraph {
let hash = new Hash();
// TODO: sort??
this.traverseAssets(bundle, asset => {
hash.writeString(
[
this.getAssetPublicId(asset),
asset.outputHash,
asset.filePath,
querystring.stringify(asset.query),
asset.type,
asset.uniqueKey,
].join(':'),
);
{
hash.writeString(
[
this.getAssetPublicId(asset),
asset.outputHash,
asset.filePath,
asset.query,
asset.type,
asset.uniqueKey,
].join(':'),
);
}
});

let hashHex = hash.finish();
Expand Down
3 changes: 1 addition & 2 deletions packages/core/core/src/Transformation.js
Expand Up @@ -24,7 +24,6 @@ import type {LoadedPlugin} from './ParcelConfig';
import path from 'path';
import {Readable} from 'stream';
import nullthrows from 'nullthrows';
import {objectSortedEntries} from '@parcel/utils';
import logger, {PluginLogger} from '@parcel/logger';
import ThrowableDiagnostic, {
errorToDiagnostic,
Expand Down Expand Up @@ -561,7 +560,7 @@ export default class Transformation {
a.value.pipeline,
a.value.hash,
a.value.uniqueKey,
a.value.query ? JSON.stringify(objectSortedEntries(a.value.query)) : '',
a.value.query ?? '',
])
.join('');

Expand Down
9 changes: 2 additions & 7 deletions packages/core/core/src/assetUtils.js
Expand Up @@ -11,7 +11,6 @@ import type {
Symbol,
SourceLocation,
Transformer,
QueryParameters,
} from '@parcel/types';
import type {
Asset,
Expand All @@ -20,7 +19,6 @@ import type {
Environment,
ParcelOptions,
} from './types';
import {objectSortedEntries} from '@parcel/utils';

import {Readable} from 'stream';
import {PluginLogger} from '@parcel/logger';
Expand All @@ -47,7 +45,7 @@ type AssetOptions = {|
hash?: ?string,
idBase?: ?string,
filePath: ProjectPath,
query?: ?QueryParameters,
query?: ?string,
type: string,
contentKey?: ?string,
mapKey?: ?string,
Expand Down Expand Up @@ -76,9 +74,6 @@ export function createAssetIdFromOptions(options: AssetOptions): string {
options.idBase != null
? options.idBase
: fromProjectPathRelative(options.filePath);
let queryString = options.query
? JSON.stringify(objectSortedEntries(options.query))
: '';

return hashString(
idBase +
Expand All @@ -88,7 +83,7 @@ export function createAssetIdFromOptions(options: AssetOptions): string {
':' +
(options.pipeline ?? '') +
':' +
queryString,
(options.query ?? ''),
);
}

Expand Down
11 changes: 7 additions & 4 deletions packages/core/core/src/public/Asset.js
Expand Up @@ -19,7 +19,6 @@ import type {
Stats,
MutableAssetSymbols as IMutableAssetSymbols,
AssetSymbols as IAssetSymbols,
QueryParameters,
BundleBehavior,
} from '@parcel/types';
import type {Asset as AssetValue, ParcelOptions} from '../types';
Expand Down Expand Up @@ -83,13 +82,14 @@ export function assetFromValue(

class BaseAsset {
#asset: CommittedAsset | UncommittedAsset;
#query /*: ?URLSearchParams */;

constructor(asset: CommittedAsset | UncommittedAsset) {
this.#asset = asset;
_assetToAssetValue.set(this, asset.value);
}

// $FlowFixMe
// $FlowFixMe[unsupported-syntax]
[inspect](): string {
return `Asset(${this.filePath})`;
}
Expand Down Expand Up @@ -117,8 +117,11 @@ class BaseAsset {
);
}

get query(): QueryParameters {
return this.#asset.value.query ?? {};
get query(): URLSearchParams {
if (!this.#query) {
this.#query = new URLSearchParams(this.#asset.value.query ?? '');
}
return this.#query;
}

get meta(): Meta {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/core/src/requests/AssetRequest.js
Expand Up @@ -12,7 +12,6 @@ import type {
import type {ConfigAndCachePath} from './ParcelConfigRequest';
import type {TransformationResult} from '../Transformation';

import {objectSortedEntries} from '@parcel/utils';
import nullthrows from 'nullthrows';
import {hashString} from '@parcel/hash';
import createParcelConfigRequest from './ParcelConfigRequest';
Expand Down Expand Up @@ -59,7 +58,7 @@ function getId(input: AssetRequestInput) {
':' +
(input.pipeline ?? '') +
':' +
(input.query ? JSON.stringify(objectSortedEntries(input.query)) : ''),
(input.query ?? ''),
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/requests/PathRequest.js
Expand Up @@ -239,7 +239,7 @@ export class ResolverRunner {
this.options.projectRoot,
resultFilePath,
),
query: result.query,
query: result.query?.toString(),
sideEffects: result.sideEffects,
code: result.code,
env: dependency.env,
Expand Down
5 changes: 2 additions & 3 deletions packages/core/core/src/types.js
Expand Up @@ -24,7 +24,6 @@ import type {
OutputFormat,
TargetDescriptor,
HMROptions,
QueryParameters,
DetailedReportOptions,
} from '@parcel/types';
import type {SharedReference} from '@parcel/workers';
Expand Down Expand Up @@ -158,7 +157,7 @@ export type Asset = {|
committed: boolean,
hash: ?string,
filePath: ProjectPath,
query: ?QueryParameters,
query: ?string,
type: string,
dependencies: Map<string, Dependency>,
bundleBehavior: ?$Values<typeof BundleBehavior>,
Expand Down Expand Up @@ -330,7 +329,7 @@ export type AssetRequestInput = {|
pipeline?: ?string,
optionsRef: SharedReference,
isURL?: boolean,
query?: ?QueryParameters,
query?: ?string,
|};
export type AssetRequestResult = Array<Asset>;
Expand Down
10 changes: 2 additions & 8 deletions packages/core/core/test/AssetGraph.test.js
Expand Up @@ -253,7 +253,6 @@ describe('AssetGraph', () => {
let req = {
filePath: toProjectPath('/index.js'),
env: DEFAULT_ENV,
query: {},
};

graph.resolveDependency(dep, req, '3');
Expand All @@ -267,7 +266,6 @@ describe('AssetGraph', () => {
let req2 = {
filePath: toProjectPath('/index.jsx'),
env: DEFAULT_ENV,
query: {},
};
graph.resolveDependency(dep, req2, '4');

Expand Down Expand Up @@ -319,7 +317,7 @@ describe('AssetGraph', () => {
});
let sourcePath = '/index.js';
let filePath = toProjectPath(sourcePath);
let req = {filePath, env: DEFAULT_ENV, query: {}};
let req = {filePath, env: DEFAULT_ENV};
graph.resolveDependency(dep, req, '3');
let assets = [
createAsset({
Expand Down Expand Up @@ -486,7 +484,7 @@ describe('AssetGraph', () => {
});
let sourcePath = '/index.js';
let filePath = toProjectPath(sourcePath);
let req = {filePath, env: DEFAULT_ENV, query: {}};
let req = {filePath, env: DEFAULT_ENV};
graph.resolveDependency(dep, req, '123');
let dep1 = createDependency({
specifier: 'dependent-asset-1',
Expand Down Expand Up @@ -566,7 +564,6 @@ describe('AssetGraph', () => {
let indexAssetGroup = {
filePath: toProjectPath('/index.js'),
env: DEFAULT_ENV,
query: {},
};
graph.setRootConnections({assetGroups: [indexAssetGroup]});
let indexFooDep = createDependency({
Expand Down Expand Up @@ -600,7 +597,6 @@ describe('AssetGraph', () => {
let fooAssetGroup = {
filePath: toProjectPath('/foo.js'),
env: DEFAULT_ENV,
query: {},
};
graph.resolveDependency(indexFooDep, fooAssetGroup, '0');
let fooAssetGroupNode = nodeFromAssetGroup(fooAssetGroup);
Expand All @@ -626,7 +622,6 @@ describe('AssetGraph', () => {
let utilsAssetGroup = {
filePath: toProjectPath('/utils.js'),
env: DEFAULT_ENV,
query: {},
};
let utilsAssetGroupNode = nodeFromAssetGroup(utilsAssetGroup);
graph.resolveDependency(fooUtilsDep, utilsAssetGroup, '0');
Expand All @@ -646,7 +641,6 @@ describe('AssetGraph', () => {
let barAssetGroup = {
filePath: toProjectPath('/bar.js'),
env: DEFAULT_ENV,
query: {},
};
graph.resolveDependency(indexBarDep, barAssetGroup, '0');
let barAssetGroupNode = nodeFromAssetGroup(barAssetGroup);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/test/BundleGraph.test.js
Expand Up @@ -83,7 +83,7 @@ function createMockAssetGraph(ids: [string, string]) {
});
let sourcePath = '/index.js';
let filePath = toProjectPath('/', sourcePath);
let req = {filePath, env: DEFAULT_ENV, query: {}};
let req = {filePath, env: DEFAULT_ENV};
graph.resolveDependency(dep, nodeFromAssetGroup(req).value, '3');

let dep1 = createDependency({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/core/test/PublicMutableBundleGraph.test.js
Expand Up @@ -151,7 +151,7 @@ function createMockAssetGraph() {
});

let filePath = toProjectPath('/', '/index.js');
let req1 = {filePath, env: DEFAULT_ENV, query: {}};
let req1 = {filePath, env: DEFAULT_ENV};
graph.resolveDependency(dep1, nodeFromAssetGroup(req1).value, '5');
graph.resolveAssetGroup(
req1,
Expand All @@ -170,7 +170,7 @@ function createMockAssetGraph() {
);

filePath = toProjectPath('/', '/index2.js');
let req2 = {filePath, env: DEFAULT_ENV, query: {}};
let req2 = {filePath, env: DEFAULT_ENV};
graph.resolveDependency(dep2, nodeFromAssetGroup(req2).value, '7');
graph.resolveAssetGroup(
req2,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/core/package-manager/src/NodePackageManager.js
Expand Up @@ -18,7 +18,6 @@ import ThrowableDiagnostic, {
md,
} from '@parcel/diagnostic';
import nativeFS from 'fs';
// $FlowFixMe this is untyped
import Module from 'module';
import path from 'path';
import semver from 'semver';
Expand Down
6 changes: 2 additions & 4 deletions packages/core/types/index.js
Expand Up @@ -25,8 +25,6 @@ export type ConfigResultWithFilePath<T> = {|
/** <code>process.env</code> */
export type EnvMap = typeof process.env;

export type QueryParameters = {[key: string]: string, ...};

export type JSONValue =
| null
| void // ? Is this okay?
Expand Down Expand Up @@ -634,7 +632,7 @@ export interface BaseAsset {
*/
+type: string;
/** The transformer options for the asset from the dependency query string. */
+query: QueryParameters;
+query: URLSearchParams;
/** The environment of the asset. */
+env: Environment;
/**
Expand Down Expand Up @@ -1455,7 +1453,7 @@ export type ResolveResult = {|
/** An optional named pipeline to use to compile the resolved file. */
+pipeline?: ?string,
/** Query parameters to be used by transformers when compiling the resolved file. */
+query?: QueryParameters,
+query?: URLSearchParams,
/** Whether the resolved file should be excluded from the build. */
+isExcluded?: boolean,
/** Overrides the priority set on the dependency. */
Expand Down

0 comments on commit aafc318

Please sign in to comment.