-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update import attribute syntax (#938)
- Loading branch information
1 parent
578fb47
commit 741b29c
Showing
29 changed files
with
223 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
"fake-imports": "https://deno.land/x/[email protected]/mod.js", | ||
"fake-dom/": "https://deno.land/x/[email protected]/src/", | ||
"puppeteer": "https://raw.githubusercontent.com/jespertheend/deno-puppeteer/7c5ed2e6e9f43d7fc27d4fa49f17db36be220956/mod.ts", | ||
"rollup": "npm:rollup@2.79.1", | ||
"$rollup": "npm:rollup@4.18.0", | ||
"rollup-plugin-jscc": "npm:[email protected]", | ||
"rollup-plugin-cleanup": "npm:[email protected]", | ||
"rollup-plugin-commonjs": "npm:@rollup/[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { rollup } from "rollup"; | ||
import { rollup } from "$rollup"; | ||
import { copy, ensureDir, walk } from "std/fs/mod.ts"; | ||
import * as path from "std/path/mod.ts"; | ||
import { minify } from "terser"; | ||
import { setCwd } from "chdir-anywhere"; | ||
import { importAssertionsPlugin } from "https://esm.sh/[email protected]?pin=v87"; | ||
import { importAssertions } from "https://esm.sh/[email protected]?pin=v87"; | ||
import postcss from "https://deno.land/x/[email protected]/mod.js"; | ||
import postcssUrl from "npm:[email protected]"; | ||
import resolveUrlObjects from "npm:[email protected]"; | ||
import { dev } from "./dev.js"; | ||
import { buildEngineSource } from "./buildEngine.js"; | ||
import { toHashString } from "std/crypto/mod.ts"; | ||
import { overrideDefines } from "./shared/overrideDefinesPlugin.js"; | ||
import { cssImportAttributesPlugin } from "./shared/rollup-css-import-attribute.js"; | ||
import { resolveWasmUrls } from "./shared/rollup-plugin-wasm-url.js"; | ||
|
||
await dev({ | ||
needsDependencies: true, | ||
|
@@ -67,7 +67,7 @@ async function setHtmlAttribute(filePath, tagComment, attributeValue, attribute | |
function rebaseCssUrl({ | ||
outputPath, | ||
}) { | ||
/** @type {import("rollup").Plugin} */ | ||
/** @type {import("$rollup").Plugin} */ | ||
const plugin = { | ||
name: "rebaseCssUrl", | ||
async load(id) { | ||
|
@@ -143,12 +143,12 @@ const bundle = await rollup({ | |
plugins: [ | ||
overrideDefines("/studio/src/studioDefines.js", studioDefines), | ||
resolveUrlObjects(), | ||
resolveWasmUrls(), | ||
rebaseCssUrl({ | ||
outputPath, | ||
}), | ||
importAssertionsPlugin(), | ||
cssImportAttributesPlugin(), | ||
], | ||
acornInjectPlugins: [importAssertions], | ||
onwarn: (message) => { | ||
if (message.code == "CIRCULAR_DEPENDENCY") return; | ||
console.error(message.message); | ||
|
@@ -166,9 +166,7 @@ const entryPointPaths = new Map(); | |
/** @type {string[]} */ | ||
const createdChunkFiles = []; | ||
for (const chunkOrAsset of output) { | ||
if (chunkOrAsset.type != "chunk") { | ||
throw new Error("Assertion failed, unexpected type: " + chunkOrAsset.type); | ||
} | ||
if (chunkOrAsset.type != "chunk") continue; | ||
if (chunkOrAsset.facadeModuleId) { | ||
entryPointPaths.set(chunkOrAsset.facadeModuleId, chunkOrAsset.fileName); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,38 +104,27 @@ export async function dev({ | |
} | ||
|
||
if (needsDependencies || needsDevDependencies) { | ||
const { dev } = await import("https://deno.land/x/dev@v0.2.0/mod.js"); | ||
const { downloadNpmPackage, esmify, addTsNocheck } = await import("https://deno.land/x/dev@v0.4.0/mod.js"); | ||
|
||
await dev({ | ||
actions: [ | ||
// required for during development, can be skipped with ci | ||
{ | ||
type: "downloadNpmPackage", | ||
package: "[email protected]", | ||
ignore: !needsDevDependencies, | ||
}, | ||
if (needsDevDependencies) { | ||
await downloadNpmPackage({ | ||
package: "[email protected]", | ||
}); | ||
} | ||
|
||
// studio dependencies | ||
{ | ||
type: "downloadNpmPackage", | ||
package: "[email protected]", | ||
}, | ||
{ | ||
type: "downloadNpmPackage", | ||
package: "[email protected]", | ||
downloadDependencies: true, | ||
}, | ||
{ | ||
type: "esmify", | ||
entryPointPath: "npm_packages/rollup/2.60.0/dist/rollup.browser.js", | ||
outputPath: "studio/deps/rollup.browser.js", | ||
}, | ||
{ | ||
type: "esmify", | ||
entryPointPath: "npm_packages/rollup-plugin-resolve-url-objects/0.0.4/main.js", | ||
outputPath: "studio/deps/rollup-plugin-resolve-url-objects.js", | ||
}, | ||
], | ||
await downloadNpmPackage({ | ||
package: "@rollup/[email protected]", | ||
}); | ||
await addTsNocheck({ | ||
path: "npm_packages/@rollup/browser/4.18.0", | ||
}); | ||
await downloadNpmPackage({ | ||
package: "[email protected]", | ||
downloadDependencies: true, | ||
}); | ||
await esmify({ | ||
entryPointPath: "npm_packages/rollup-plugin-resolve-url-objects/0.0.4/main.js", | ||
outFile: "studio/deps/rollup-plugin-resolve-url-objects.js", | ||
}); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* A rollup plugin that allows you to import css files like so: | ||
* ```js | ||
* import sheet from "./path/to/style.css" with { type: "css" } | ||
* document.adoptedStyleSheets = [sheet]; | ||
* ``` | ||
* @returns {import("$rollup").Plugin} | ||
*/ | ||
export function cssImportAttributesPlugin() { | ||
return { | ||
name: "css-import-attributes", | ||
async resolveId(source, importer, options) { | ||
const { attributes } = options; | ||
if ("type" in attributes && attributes.type == "css") { | ||
const resolution = await this.resolve(source, importer, options); | ||
if (!resolution || resolution.external) return resolution; | ||
return { | ||
id: resolution.id, | ||
meta: { | ||
cssImportAttributes: { | ||
isCssType: true, | ||
}, | ||
}, | ||
}; | ||
} | ||
return null; | ||
}, | ||
transform(code, id) { | ||
const moduleInfo = this.getModuleInfo(id); | ||
const meta = moduleInfo?.meta; | ||
if (meta && "cssImportAttributes" in meta && meta.cssImportAttributes.isCssType) { | ||
const newCode = `const sheet = new CSSStyleSheet();sheet.replaceSync(\`${code}\`);export default sheet;`; | ||
return { code: newCode }; | ||
} | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as stdPath from "std/path/mod.ts"; | ||
|
||
/** @type {import("$rollup").PluginImpl} */ | ||
export function resolveWasmUrls() { | ||
return { | ||
name: "resolve-wasm-urls", | ||
async transform(code, id) { | ||
const re = /new\s+URL\s*\(\s*['"`](?<wasmUrl>.+\.wasm)['"`]\s*,\s*import\.meta\.url\s*\)/gid; | ||
for (const match of code.matchAll(re)) { | ||
if (!match.indices) continue; | ||
if (!match.indices.groups) continue; | ||
if (!match.groups) continue; | ||
const startUrlIndex = match.indices.groups.wasmUrl[0] - 1; | ||
const endUrlIndex = match.indices.groups.wasmUrl[1] + 1; | ||
let wasmUrl = match.groups.wasmUrl; | ||
if (!wasmUrl.match(/^.?.?\//)) { | ||
wasmUrl = "./" + wasmUrl; | ||
} | ||
|
||
const resolveResult = await this.resolve(wasmUrl, id, { | ||
attributes: { | ||
type: "webassembly", | ||
}, | ||
}); | ||
if (!resolveResult) continue; | ||
|
||
const parsedPath = stdPath.parse(resolveResult.id); | ||
|
||
const source = await Deno.readFile(resolveResult.id); | ||
const hashBuffer = await crypto.subtle.digest("SHA-256", source); | ||
const hashArray = Array.from(new Uint8Array(hashBuffer)); | ||
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join(""); | ||
const hash = hashHex.slice(0, 8); | ||
|
||
const chunkRefId = this.emitFile({ | ||
type: "asset", | ||
fileName: `${parsedPath.name}-${hash}.wasm`, | ||
source, | ||
}); | ||
const newUrl = `import.meta.ROLLUP_FILE_URL_${chunkRefId}`; | ||
|
||
code = code.substring(0, startUrlIndex) + newUrl + code.substring(endUrlIndex); | ||
} | ||
|
||
return { | ||
code, | ||
}; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,52 +54,9 @@ License: MIT | |
By: Rich Harris | ||
Repository: rollup/plugins | ||
--------------------------------------- | ||
## acorn | ||
License: MIT | ||
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine | ||
Repository: https://github.com/acornjs/acorn.git | ||
> MIT License | ||
> | ||
> Copyright (C) 2012-2022 by various contributors (see AUTHORS) | ||
> | ||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in | ||
> all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
> THE SOFTWARE. | ||
--------------------------------------- | ||
## acorn-import-assertions | ||
License: MIT | ||
By: Sven Sauleau | ||
Repository: https://github.com/xtuc/acorn-import-assertions | ||
--------------------------------------- | ||
## acorn-walk | ||
License: MIT | ||
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine | ||
Repository: https://github.com/acornjs/acorn.git | ||
> MIT License | ||
> The MIT License (MIT) | ||
> | ||
> Copyright (C) 2012-2020 by various contributors (see AUTHORS) | ||
> Copyright (c) 2019 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors) | ||
> | ||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -151,7 +108,8 @@ Repository: sindresorhus/binary-extensions | |
> MIT License | ||
> | ||
> Copyright (c) 2019 Sindre Sorhus <[email protected]> (https://sindresorhus.com), Paul Miller (https://paulmillr.com) | ||
> Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com) | ||
> Copyright (c) Paul Miller (https://paulmillr.com) | ||
> | ||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
> | ||
|
@@ -168,7 +126,7 @@ Repository: micromatch/braces | |
> The MIT License (MIT) | ||
> | ||
> Copyright (c) 2014-2018, Jon Schlinkert. | ||
> Copyright (c) 2014-present, Jon Schlinkert. | ||
> | ||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -451,7 +409,7 @@ Repository: git+https://github.com/Rich-Harris/is-reference.git | |
## locate-character | ||
License: MIT | ||
By: Rich Harris | ||
Repository: Rich-Harris/locate-character | ||
Repository: git+https://gitlab.com/Rich-Harris/locate-character.git | ||
--------------------------------------- | ||
|
@@ -615,7 +573,7 @@ Repository: https://github.com/tapjs/signal-exit.git | |
> The ISC License | ||
> | ||
> Copyright (c) 2015, Contributors | ||
> Copyright (c) 2015-2023 Benjamin Coe, Isaac Z. Schlueter, and Contributors | ||
> | ||
> Permission to use, copy, modify, and/or distribute this software | ||
> for any purpose with or without fee is hereby granted, provided | ||
|
Oops, something went wrong.