Skip to content

Commit

Permalink
Generate ES6/ES2015 Javascript for Gecko mozilla-central (#2050)
Browse files Browse the repository at this point in the history
* Generate ES6/ES2015 Javascript for Gecko mozilla-central

* Output with sys.mjs extension

* Add mozilla-central prettier config

* Use module wording

* Do not export as default, gecko tests won't pass
  • Loading branch information
leplatrem committed Jun 20, 2023
1 parent 49c5885 commit 50216e9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bin/dist-fx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function getVersionFromPackageJson(): string {
}

const rollupOutput = "dist/temp.js";
const destination = "dist/moz-kinto-http-client.js";
const destination = "dist/moz-kinto-http-client.sys.mjs";

mkdir("-p", "dist");

Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ This should have created the following assets, with the current version in the f
- `dist/kinto.js`: Development version, unminified, embedding source maps;
- `dist/kinto.min.js`: Production version, minified, no source maps;
- `dist/kinto.noshim.js`: Production version, minified, no polyfills;
- `dist/moz-kinto-offline-client.js`: Firefox internal component bundle (for Mozilla specific use).
- `dist/moz-kinto-http-client.sys.mjs`: Firefox internal component bundle (for Mozilla specific use).

Once a new version is packaged and [published to npm](#publishing-to-npm), the [unpkg](https://unpkg.com/ service) makes ready-to-use kinto.js assets available from the following urls:

Expand Down
16 changes: 16 additions & 0 deletions fx-src/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Original:
// https://searchfox.org/mozilla-central/rev/fb55a4ee44a9a95d099aa806ca494eb988252ded/.prettierrc.js

/* eslint-env node */

module.exports = {
arrowParens: "avoid",
endOfLine: "lf",
printWidth: 80,
tabWidth: 2,
trailingComma: "es5",
};
14 changes: 2 additions & 12 deletions fx-src/jsm_prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";

/*
*
* This file is generated from kinto.js - do not modify directly.
*/

const global = this;
const globalThis = this;

var EXPORTED_SYMBOLS = ["KintoHttpClient"];

const { setTimeout, clearTimeout } = ChromeUtils.importESModule("resource://gre/modules/Timer.sys.mjs");
const { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs");
XPCOMUtils.defineLazyGlobalGetters(global, ["fetch"]);
import { setTimeout, clearTimeout } from "resource://gre/modules/Timer.sys.mjs";
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
"cs-check": "prettier -l \"{src,test,bin}/**/*.{js,ts}\"",
"cs-format": "prettier \"{src,test,bin}/**/*.{js,ts}\" --write",
"demo": "npm run build-demo && http-server demo",
"dist": "npx cross-env NODE_ENV=production rollup -c && npm run dist:fx",
"dist": "npx cross-env NODE_ENV=production rollup -c && npm run dist:fx && npm run dist:fx:format",
"dist:dev": "npx rollup -c && npm run dist:fx",
"dist:fx": "npx ts-node --skip-project bin/dist-fx.ts",
"dist:fx:format": "npx prettier --config fx-src/.prettierrc.js dist/ --write",
"lint": "eslint \"src/**/*.{js,ts}\" \"test/**/*.{js,ts}\"",
"publish-demo": "npm run dist-prod && cp dist/kinto.js demo/kinto.js && gh-pages -d demo",
"publish-to-npm": "npm run dist && npm run build && npm publish",
Expand Down
6 changes: 4 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ const geckoBuild = {
output: [
{
file: "dist/temp.js",
format: "umd",
format: "module",
name: "KintoHttpClient",
generatedCode: {
objectShorthand: true,
},
},
],
plugins: [
Expand All @@ -25,7 +28,6 @@ const geckoBuild = {
typescript({
include: ["*.ts+(|x)", "**/*.ts+(|x)", "*.js", "**/*.js"],
}),
commonjs({ ignoreGlobal: true }),
],
};

Expand Down
10 changes: 4 additions & 6 deletions src/http/index.fx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
* limitations under the License.
*/

/* @ts-ignore */
import { EventEmitter } from "resource://gre/modules/EventEmitter.sys.mjs";

import KintoClientBase, { KintoClientOptions } from "./base";
import * as errors from "./errors";
import { EventEmitter as ee } from "events";

declare const ChromeUtils: any;
const { EventEmitter } = ChromeUtils.importESModule(
"resource://gre/modules/EventEmitter.sys.mjs"
) as { EventEmitter: any };

export default class KintoHttpClient extends KintoClientBase {
export class KintoHttpClient extends KintoClientBase {
constructor(remote: string, options: Partial<KintoClientOptions> = {}) {
const events = {};
EventEmitter.decorate(events);
Expand Down

0 comments on commit 50216e9

Please sign in to comment.