Skip to content

Commit

Permalink
deprecate: remove all deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Nov 19, 2023
1 parent 28bc548 commit a7f46bf
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 282 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist
node_modules
lib
yarn.lock
.vscode
165 changes: 10 additions & 155 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,6 @@ export interface GeneratorOptions {
*/
lock?: LockResolutions;

/**
* When using a lockfile, do not modify any existing resolutions, and use
* existing resolutions whenever possible for new locks.
*
* @deprecated Use install/link/update to manage dependencies.
*/
freeze?: boolean;

/**
* When using a lockfile, force update all touched resolutions to latest.
*
* @deprecated
*/
latest?: boolean;

/**
* Support tracing CommonJS dependencies locally. This is necessary if you
* are using the "nodemodules" provider and have CommonJS dependencies.
Expand Down Expand Up @@ -357,11 +342,6 @@ export class Generator {
*/
installCnt = 0;

// @deprecated
private freeze: boolean | null;
// @deprecated
private latest: boolean | null;

/**
* Constructs a new Generator instance.
*
Expand Down Expand Up @@ -401,8 +381,6 @@ export class Generator {
cache = true,
fetchOptions = {},
ignore = [],
freeze,
latest,
commonJS = false,
}: GeneratorOptions = {}) {
// Initialise the debug logger:
Expand Down Expand Up @@ -508,10 +486,6 @@ export class Generator {
// Reconstruct constraints and locks from the input map:
this.map = new ImportMap({ mapUrl: this.mapUrl, rootUrl: this.rootUrl });
if (inputMap) this.addMappings(inputMap);

// Set deprecated global resolution options for backwards compat:
this.latest = latest;
this.freeze = freeze;
}

/**
Expand Down Expand Up @@ -559,37 +533,6 @@ export class Generator {
return JSON.parse(JSON.stringify(this.traceMap.installer.installs));
}

/**
* Trace and pin a module, installing all dependencies necessary into the map
* to support its execution including static and dynamic module imports.
*
* @deprecated Use "link" instead.
*/
async pin(
specifier: string,
parentUrl?: string
): Promise<{
staticDeps: string[];
dynamicDeps: string[];
}> {
return this.link(specifier, parentUrl);
}

/**
* Trace a module, installing all dependencies necessary into the map
* to support its execution including static and dynamic module imports.
*
* @param specifier Module to trace
* @param parentUrl Optional parent URL
* @deprecated Use "link" instead.
*/
async traceInstall(
specifier: string | string[],
parentUrl?: string
): Promise<{ staticDeps: string[]; dynamicDeps: string[] }> {
return this.link(specifier, parentUrl);
}

/**
* Link a module, installing all dependencies necessary into the map
* to support its execution including static and dynamic module imports.
Expand All @@ -598,14 +541,19 @@ export class Generator {
* @param parentUrl Optional parent URL
*/
async link(
specifier: string | string[],
specifier?: string | string[],
parentUrl?: string
): Promise<{ staticDeps: string[]; dynamicDeps: string[] }> {
if (typeof specifier === "string") specifier = [specifier];
let error = false;
if (this.installCnt++ === 0) this.traceMap.startInstall();
specifier = specifier.map((specifier) => specifier.replace(/\\/g, "/"));
await this.traceMap.processInputMap;
if (!specifier || specifier.length === 0) {
const { map, staticDeps, dynamicDeps } = await this.traceMap.finishInstall();
this.map = map;
return { staticDeps, dynamicDeps };
}
specifier = specifier.map((specifier) => specifier.replace(/\\/g, "/"));
try {
await Promise.all(
specifier.map((specifier) =>
Expand Down Expand Up @@ -670,79 +618,6 @@ export class Generator {
return impts;
}

/**
* Generate and inject an import map for an HTML file
*
* @deprecated Instead use:
* const pins = await generator.addMappings(html, mapUrl, rootUrl);
* return await generator.htmlInject(html, { pins, htmlUrl: mapUrl, rootUrl, preload, integrity, whitespace, esModuleShims, comment });
*
* Traces the module scripts of the HTML via link and install
* for URL-like specifiers and bare specifiers respectively.
*
* Injects the final generated import map returning the injected HTML
*
* @param html String
* @param injectOptions Injection options
*
* Injection options are: `htmlUrl`, `preload`, `integrity`, `whitespace`
* and `esModuleShims`. The default is `\{ esModuleShims: true, whitespace: true \}`.
*
* ES Module shims will be resolved to the latest version against the provider
*
* Example:
*
* ```js
* const outputHtml = await generator.htmlGenerate(`
* <!doctype html>
* <script type="module">import 'react'</script>
* `);
* // <!doctype html>
* // <!-- Generated by @jspm/generator - https://github.com/jspm/generator -->
* // <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.1/dist/es-module-shims.js"></script>
* // <script type="importmap">
* // {...}
* // </script>
* // <script type="module">import 'react'</script>
* ```
*
*/
async htmlGenerate(
html: string,
{
mapUrl,
rootUrl,
htmlUrl,
preload = false,
integrity = false,
whitespace = true,
esModuleShims = true,
comment = true,
}: {
mapUrl?: string | URL;
rootUrl?: string | URL | null;
htmlUrl?: string | URL | null;
preload?: boolean | "all" | "static";
integrity?: boolean;
whitespace?: boolean;
esModuleShims?: string | boolean;
comment?: boolean | string;
} = {}
): Promise<string> {
if (typeof mapUrl === "string") mapUrl = new URL(mapUrl);
const pins = await this.addMappings(html, mapUrl, rootUrl);
return await this.htmlInject(html, {
pins,
htmlUrl: htmlUrl || mapUrl, // backwards compatibility
rootUrl,
preload,
integrity,
whitespace,
esModuleShims,
comment,
});
}

/**
* Inject the import map into the provided HTML source
*
Expand All @@ -755,8 +630,8 @@ export class Generator {
{
trace = false,
pins = !trace,
htmlUrl,
rootUrl,
htmlUrl = this.mapUrl,
rootUrl = this.rootUrl,
preload = false,
integrity = false,
whitespace = true,
Expand All @@ -781,7 +656,7 @@ export class Generator {
if (integrity) preload = true;
if (this.installCnt !== 0)
throw new JspmError(
"htmlGenerate cannot run alongside other install ops"
"htmlInject cannot run alongside other install ops"
);

const analysis = analyzeHtml(html, htmlUrl);
Expand Down Expand Up @@ -1005,9 +880,6 @@ export class Generator {
install?: string | Install | (string | Install)[],
mode?: InstallMode
): Promise<void | { staticDeps: string[]; dynamicDeps: string[] }> {
// Backwards-compatibility for deprecated options:
if (this.latest) mode ??= "latest-primaries";
if (this.freeze) mode ??= "freeze";

// If there are no arguments, then we reinstall all the top-level locks:
if (install === null || install === undefined) {
Expand Down Expand Up @@ -1138,23 +1010,6 @@ export class Generator {
}
}

/**
* Locking install, retraces all top-level pins but does not change the
* versions of anything (similar to "npm ci").
*
* @deprecated Use install() with the "freeze: true" option.
*/
async reinstall() {
if (this.installCnt++ === 0) this.traceMap.startInstall();
await this.traceMap.processInputMap;
if (--this.installCnt === 0) {
const { map, staticDeps, dynamicDeps } =
await this.traceMap.finishInstall();
this.map = map;
return { staticDeps, dynamicDeps };
}
}

/**
* Updates the versions of the given packages to the latest versions
* compatible with their parent's package.json ranges. If no packages are
Expand Down
3 changes: 1 addition & 2 deletions test/api/freeze.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import assert from "assert";

async function checkScenario(scenario) {
const generator = new Generator({
freeze: true,
mapUrl: new URL("./local/freeze", import.meta.url).href,
baseUrl: new URL("./local/freeze", import.meta.url).href,
inputMap: scenario.map ?? {},
Expand All @@ -30,7 +29,7 @@ async function checkScenario(scenario) {

// install dependencies:
try {
await Promise.all(scenario.install.map((pkg) => generator.install(pkg)));
await Promise.all(scenario.install.map((pkg) => generator.link(pkg)));
} catch (err) {
if (!scenario.expect) return; // expected to throw, all good
throw err;
Expand Down
6 changes: 4 additions & 2 deletions test/api/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const generator = new Generator({
},
mapUrl: import.meta.url,
env: ["production", "browser"],
freeze: true, // lock versions
resolutions: {
'lit': '2.6.1'
}
});

// Install with no arguments should install all top-level pins.
Expand All @@ -27,7 +29,7 @@ assert.strictEqual(
);

// Installing a new dependency with freeze should not throw:
await generator.install(["lit@2.6.1"]);
await generator.link(["lit"]);
json = generator.getMap();

assert.strictEqual(
Expand Down
2 changes: 1 addition & 1 deletion test/api/providerswitch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const generator = new Generator({

// The generator should swap the provider from skypack to jspm.io.
// TODO: once we land defaultProvider changes this test will break
await generator.reinstall();
await generator.install();

const json = generator.getMap();
assert(json.imports.react.startsWith("https://ga.jspm.io/npm:"));
4 changes: 2 additions & 2 deletions test/api/reenv.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import assert from "assert";
env: ["production", "browser"],
});

await generator.reinstall();
await generator.link();
const json = generator.getMap();

assert.strictEqual(
Expand Down Expand Up @@ -50,7 +50,7 @@ import assert from "assert";
},
});

await generator.reinstall();
await generator.link();

const json = generator.getMap();

Expand Down
14 changes: 8 additions & 6 deletions test/html/breaks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ const esmsUrl =
generator.traceMap.installer.defaultProvider
)) + "dist/es-module-shims.js";

assert.strictEqual(
await generator.htmlGenerate(
`<!DOCTYPE html>
const html =
`<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -62,9 +61,12 @@ assert.strictEqual(
<div id="root"></div>
</body>
</html>`,
{ preload: true }
),
</html>`;

const pins = await generator.addMappings(html);
const res = await generator.htmlInject(html, { pins, preload: true });

assert.strictEqual(res,
"<!DOCTYPE html>\n" +
'<html lang="en">\n' +
"\n" +
Expand Down
13 changes: 7 additions & 6 deletions test/html/emptymap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ const esmsUrl =
generator.traceMap.installer.defaultProvider
)) + "dist/es-module-shims.js";

assert.strictEqual(
await generator.htmlGenerate(
`<!DOCTYPE html>
const html = `<!DOCTYPE html>
<script type="importmap"></script>
`,
{ preload: true }
),
`;

const pins = await generator.addMappings(html);
const res = await generator.htmlInject(html, { pins, preload: true });

assert.strictEqual(res,
"<!DOCTYPE html>\n" +
"\n" +
"<!-- Generated by @jspm/generator - https://github.com/jspm/generator -->\n" +
Expand Down
6 changes: 2 additions & 4 deletions test/html/indent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ async function checkIndent(html, expected) {
},
});

const res = await generator.htmlGenerate(html, {
preload: true,
rootUrl: generator.rootUrl,
});
const pins = await generator.addMappings(html);
const res = await generator.htmlInject(html, { pins, preload: true });

assert.strictEqual(res.trim(), expected.trim());
}
Expand Down
Loading

0 comments on commit a7f46bf

Please sign in to comment.