Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process webmanifests #4313

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/configs/default/index.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"bundler": "@parcel/bundler-default",
"transformers": {
"types:*.{ts,tsx}": ["@parcel/transformer-typescript-types"],
"bundle-text:*": ["@parcel/transformer-inline-string", "..."],
"data-url:*": ["@parcel/transformer-inline-string", "..."],
"types:*.{ts,tsx}": ["@parcel/transformer-typescript-types"],
"webmanifest:*": ["@parcel/transformer-webmanifest"],
"*.{js,mjs,jsm,jsx,es6,cjs,ts,tsx}": [
"@parcel/transformer-react-refresh-babel",
"@parcel/transformer-babel",
Expand Down Expand Up @@ -51,7 +52,7 @@
"*.css": "@parcel/packager-css",
"*.js": "@parcel/packager-js",
"*.ts": "@parcel/packager-ts",
"*.jsonld": "@parcel/packager-raw-url",
"*.{jsonld,webmanifest}": "@parcel/packager-raw-url",
"*": "@parcel/packager-raw"
},
"resolvers": ["@parcel/resolver-default"],
Expand Down
5 changes: 3 additions & 2 deletions packages/configs/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@parcel/transformer-json": "^2.0.0-alpha.3.1",
"@parcel/transformer-jsonld": "^2.0.0-alpha.3.1",
"@parcel/transformer-less": "^2.0.0-alpha.3.1",
"@parcel/transformer-mdx": "^2.0.0-alpha.3.1",
"@parcel/transformer-postcss": "^2.0.0-alpha.3.1",
"@parcel/transformer-posthtml": "^2.0.0-alpha.3.1",
"@parcel/transformer-pug": "^2.0.0-alpha.3.1",
Expand All @@ -54,8 +55,8 @@
"@parcel/transformer-sugarss": "^2.0.0-alpha.3.1",
"@parcel/transformer-toml": "^2.0.0-alpha.3.1",
"@parcel/transformer-typescript-types": "^2.0.0-alpha.3.1",
"@parcel/transformer-yaml": "^2.0.0-alpha.3.1",
"@parcel/transformer-mdx": "^2.0.0-alpha.3.1"
"@parcel/transformer-webmanifest": "^2.0.0-alpha.3.1",
"@parcel/transformer-yaml": "^2.0.0-alpha.3.1"
},
"peerDependencies": {
"@parcel/core": "^2.0.0-alpha.3.1"
Expand Down
35 changes: 18 additions & 17 deletions packages/core/core/src/TargetResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default class TargetResolver {
name,
_descriptor,
null,
{targets: optionTargets},
JSON.stringify({targets: optionTargets}, null, '\t'),
);
if (!distDir) {
let optionTargetsString = JSON.stringify(optionTargets, null, '\t');
Expand Down Expand Up @@ -233,7 +233,7 @@ export default class TargetResolver {
pkgContents,
'/engines',
'Invalid engines in package.json',
) || {};
) ?? {};
if (!pkgEngines.browsers) {
let browserslistBrowsers = browserslist.loadConfig({path: rootDir});
if (browserslistBrowsers) {
Expand Down Expand Up @@ -467,7 +467,7 @@ export default class TargetResolver {
function parseEngines(
engines: mixed,
pkgPath: ?FilePath,
pkgContents: string | mixed,
pkgContents: ?string,
prependKey: string,
message: string,
): Engines | typeof undefined {
Expand All @@ -476,11 +476,8 @@ function parseEngines(
} else {
validateSchema.diagnostic(
ENGINES_SCHEMA,
engines,
pkgPath,
pkgContents,
{data: engines, source: pkgContents, filePath: pkgPath, prependKey},
'@parcel/core',
prependKey,
message,
);

Expand All @@ -493,15 +490,17 @@ function parseDescriptor(
targetName: string,
descriptor: mixed,
pkgPath: ?FilePath,
pkgContents: string | mixed,
pkgContents: ?string,
): TargetDescriptor | PackageTargetDescriptor {
validateSchema.diagnostic(
DESCRIPTOR_SCHEMA,
descriptor,
pkgPath,
pkgContents,
{
data: descriptor,
source: pkgContents,
filePath: pkgPath,
prependKey: `/targets/${targetName}`,
},
'@parcel/core',
`/targets/${targetName}`,
`Invalid target descriptor for target "${targetName}"`,
);

Expand All @@ -513,15 +512,17 @@ function parseCommonTargetDescriptor(
targetName: string,
descriptor: mixed,
pkgPath: ?FilePath,
pkgContents: string | mixed,
pkgContents: ?string,
): TargetDescriptor | PackageTargetDescriptor | false {
validateSchema.diagnostic(
COMMON_TARGET_DESCRIPTOR_SCHEMA,
descriptor,
pkgPath,
pkgContents,
{
data: descriptor,
source: pkgContents,
filePath: pkgPath,
prependKey: `/targets/${targetName}`,
},
'@parcel/core',
`/targets/${targetName}`,
`Invalid target descriptor for target "${targetName}"`,
);

Expand Down
5 changes: 1 addition & 4 deletions packages/core/core/src/loadParcelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,8 @@ export function validateConfigFile(

validateSchema.diagnostic(
ParcelConfigSchema,
config,
relativePath,
JSON.stringify(config, null, '\t'),
{data: config, filePath: relativePath},
'@parcel/core',
'',
'Invalid Parcel Config',
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/public/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class MutableAsset extends BaseAsset implements IMutableAsset {
return this.#asset.setAST(ast);
}

addURLDependency(url: string, opts: $Shape<DependencyOptions>): string {
addURLDependency(url: string, opts: ?$Shape<DependencyOptions>): string {
return this.addDependency({
moduleSpecifier: url,
isURL: true,
Expand Down
5 changes: 3 additions & 2 deletions packages/core/diagnostic/src/diagnostic.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ export default class ThrowableDiagnostic extends Error {

// ids.key has to be "/some/parent/child"
export function generateJSONCodeHighlights(
code: string,
data: string | {|data: any, pointers: any|},
ids: Array<{|key: string, type?: ?'key' | 'value', message?: string|}>,
): Array<DiagnosticCodeHighlight> {
// json-source-map doesn't support a tabWidth option (yet)
let map = jsonMap.parse(code.replace(/\t/g, ' '));
let map =
typeof data === 'string' ? jsonMap.parse(data.replace(/\t/g, ' ')) : data;
return ids.map(({key, type, message}) => {
let pos = nullthrows(map.pointers[key]);
return {
Expand Down
47 changes: 0 additions & 47 deletions packages/core/integration-tests/test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,53 +550,6 @@ describe('html', function() {
]);
});

it.skip('should support webmanifest', async function() {
let b = await bundle(
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: [],
},
],
},
],
});
});

it.skip("should treat webmanifest as an entry module so it doesn't get content hashed", async function() {
const b = await bundle(
path.join(__dirname, '/integration/html-manifest/index.html'),
);

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'),
'utf8',
);
assert(html.includes('<link rel="manifest" href="/manifest.webmanifest">'));
});

it('should bundle svg files correctly', async function() {
let b = await bundle(
path.join(__dirname, '/integration/html-svg/index.html'),
Expand Down

This file was deleted.

This file was deleted.

Empty file.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!doctype html>
<html>
<head><link rel="manifest" href="./manifest.json"></head>
<body></body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "pwa-webmanifest-example",
"icons": [
{
"src": "icon.png",
"sizes": "100x100",
"type": "image/png"
}
],
"screenshots": [
{
"src": "screenshot.png",
"sizes": "100x100",
"type": "image/png"
}
]
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!doctype html>
<html>
<head><link rel="manifest" href="./manifest.json"></head>
<body></body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "pwa-webmanifest-example",
"icons": [
{
"src": "icon.png",
"sizes": "100x100",
"type": "image/png"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!doctype html>
<html>
<head><link rel="manifest" href="./manifest.webmanifest"></head>
<body></body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "pwa-webmanifest-example",
"icons": [
{
"src": "icon.png",
"sizes": "100x100",
"type": "image/png"
},
{
"sizes": "100x100",
"type": "image/png"
},
{}
],
"screenshots": {}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html>
<head><link rel="manifest" href="manifest.webmanifest"></head>
<head><link rel="manifest" href="./manifest.webmanifest"></head>
<body></body>
</html>
</html>
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"name": "example",
"icons": [
{
"src": "some.txt",
"sizes": "192x192",
"type": "image/png"
}
],
"display": "standalone"
}
"name": "pwa-webmanifest-example",
"icons": [
{
"src": "icon.png",
"sizes": "100x100",
"type": "image/png"
}
],
"screenshots": [
{
"src": "screenshot.png",
"sizes": "100x100",
"type": "image/png"
}
]
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.