Skip to content
Merged
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
10 changes: 10 additions & 0 deletions callbacks.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @deprecated `'ably/callbacks'` was the v1 callback API entry point and has been removed in ably-js v2.
* v2 is promise-only — import from `'ably'` directly and switch to `await` / `.then()`.
*
* Importing this subpath throws at module load with the migration link.
*
* @see https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md
*/
declare const ablyCallbacksV1EntryPointRemoved: never;
export = ablyCallbacksV1EntryPointRemoved;
6 changes: 6 additions & 0 deletions callbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

const err = new Error("'ably/callbacks' was the v1 callback API entry point and is no longer available.");
err.hint =
"ably-js v2 is promise-only — import from 'ably' directly and switch to await / .then(). See https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md";
throw err;
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,26 @@
"types": "./liveobjects.d.ts",
"default": "./build/liveobjects.js"
}
},
"./promises": {
"types": "./promises.d.ts",
"default": "./promises.js"
},
"./callbacks": {
"types": "./callbacks.d.ts",
"default": "./callbacks.js"
}
},
"files": [
"build/**",
"ably.d.ts",
"callbacks.d.ts",
"callbacks.js",
"liveobjects.d.ts",
"liveobjects.d.mts",
"modular.d.ts",
"promises.d.ts",
"promises.js",
"push.d.ts",
"resources/**",
"src/**",
Expand Down
10 changes: 10 additions & 0 deletions promises.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @deprecated `'ably/promises'` was the v1 entry point and is no longer available in ably-js v2.
* v2 is promise-only — import from `'ably'` directly.
*
* Importing this subpath throws at module load with the migration link.
*
* @see https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md
*/
declare const ablyPromisesV1EntryPointRemoved: never;
export = ablyPromisesV1EntryPointRemoved;
6 changes: 6 additions & 0 deletions promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

const err = new Error("'ably/promises' was the v1 entry point and is no longer available.");
err.hint =
"ably-js v2 is promise-only — import from 'ably' directly. See https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md";
throw err;
68 changes: 68 additions & 0 deletions test/unit/legacy-import-shims.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

define(['chai'], function (chai) {
const { expect } = chai;
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..', '..');

describe('legacy v1 import-path shims', function () {
function loadShim(relPath) {
const abs = path.join(repoRoot, relPath);
delete require.cache[abs];
require(abs);
}

it("'ably/promises' shim throws naming the v1 entry point, with a hint pointing at the migration guide", function () {
let caught;
try {
loadShim('promises.js');
} catch (err) {
caught = err;
}
expect(caught).to.be.an.instanceOf(Error);
expect(caught.message).to.match(/'ably\/promises' was the v1 entry point/);
expect(caught.hint).to.be.a('string');
expect(caught.hint).to.match(/promise-only/);
expect(caught.hint).to.match(/migration-guides\/v2\/lib\.md/);
});

it("'ably/callbacks' shim throws naming the v1 callback API, with a hint pointing at the migration guide", function () {
let caught;
try {
loadShim('callbacks.js');
} catch (err) {
caught = err;
}
expect(caught).to.be.an.instanceOf(Error);
expect(caught.message).to.match(/'ably\/callbacks' was the v1 callback API entry point/);
expect(caught.hint).to.be.a('string');
expect(caught.hint).to.match(/await/);
expect(caught.hint).to.match(/migration-guides\/v2\/lib\.md/);
});

it('package.json exports map wires the legacy subpaths to the shim files and their types', function () {
const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));

expect(pkg.exports['./promises'], "exports['./promises']").to.deep.equal({
types: './promises.d.ts',
default: './promises.js',
});
expect(pkg.exports['./callbacks'], "exports['./callbacks']").to.deep.equal({
types: './callbacks.d.ts',
default: './callbacks.js',
});

for (const file of ['promises.js', 'promises.d.ts', 'callbacks.js', 'callbacks.d.ts']) {
expect(fs.existsSync(path.join(repoRoot, file)), file).to.equal(true);
}
});

it("'files' array ships the legacy shim files in the published package", function () {
const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
for (const file of ['promises.js', 'promises.d.ts', 'callbacks.js', 'callbacks.d.ts']) {
expect(pkg.files, `files[] should include ${file}`).to.include(file);
}
});
});
});
Loading