From 8084f8ff300bc1698050c2f9311aa197e5d77d7f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 14:10:40 -0600 Subject: [PATCH 01/12] ref!: use default parameters to break compatibility with older browsers --- ajquery.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ajquery.js b/ajquery.js index 0ad0405..5841bd5 100644 --- a/ajquery.js +++ b/ajquery.js @@ -1,7 +1,7 @@ -function $(sel, el) { - return (el || document).querySelector(sel); +function $(sel, $parent = document) { + return $parent.querySelector(sel); } -function $$(sel, el) { - return Array.from((el || document).querySelectorAll(sel)); +function $$(sel, $parent = document) { + return Array.from($parent.querySelectorAll(sel)); } From 607f69e402a7d178d152c2932f493ab010c4374b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 17:36:58 -0600 Subject: [PATCH 02/12] doc: .textContent for modernized usage example --- example.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.html b/example.html index 5534620..3eaa7f2 100644 --- a/example.html +++ b/example.html @@ -6,6 +6,6 @@ From dc70e6caab53c799ed8b4e65bf8619bb1f945a3e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 14:15:11 -0600 Subject: [PATCH 03/12] ref: dumb it down, full Ai ahead! --- ajquery.js | 11 +++++++---- example.html | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ajquery.js b/ajquery.js index 5841bd5..ea4e00a 100644 --- a/ajquery.js +++ b/ajquery.js @@ -1,7 +1,10 @@ -function $(sel, $parent = document) { - return $parent.querySelector(sel); +function $(cssSelector, $parent = document) { + let $child = $parent.querySelector(cssSelector); + return $child; } -function $$(sel, $parent = document) { - return Array.from($parent.querySelectorAll(sel)); +function $$(cssSelector, $parent = document) { + let nodeList = $parent.querySelectorAll(cssSelector); + let $children = Array.from(nodeList); + return $children; } diff --git a/example.html b/example.html index 3eaa7f2..6e4902b 100644 --- a/example.html +++ b/example.html @@ -6,6 +6,7 @@ From 2944bdbc4cdae399c70f5f0191edcc2d80a982dc Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 16:23:40 -0600 Subject: [PATCH 04/12] doc: add types to define args --- ajquery.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ajquery.js b/ajquery.js index ea4e00a..caaa8ab 100644 --- a/ajquery.js +++ b/ajquery.js @@ -1,8 +1,18 @@ +/** + * Select first matching element, just like console $ + * @param {String} cssSelector + * @param {ParentNode} [$parent=document] + */ function $(cssSelector, $parent = document) { let $child = $parent.querySelector(cssSelector); return $child; } +/** + * Select all matching child elements as a JS Array, just like console $$ + * @param {String} cssSelector + * @param {ParentNode} [$parent=document] + */ function $$(cssSelector, $parent = document) { let nodeList = $parent.querySelectorAll(cssSelector); let $children = Array.from(nodeList); From 6566c66af60e31447f3ea87497a275227a5f8e2f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 17:29:03 -0600 Subject: [PATCH 05/12] feat: add cjs and mjs --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++---- ajquery.cjs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ ajquery.mjs | 32 ++++++++++++++++++++++++++++++++ example.html | 11 +++++++++++ package.json | 23 ++++++++++++++++++++--- 5 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 ajquery.cjs create mode 100644 ajquery.mjs diff --git a/README.md b/README.md index dbc793c..df40cc0 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ The fastest, most lightweight, fewest dependency jQuery alternative. -Development Build: 145B (with comments) \ -Production Build: 103B (min + gz) +Development Build: 572B (types + comments) \ +Production Build: 146B (min + gz) ## Example Usage @@ -18,11 +18,15 @@ console.log("innerText:", $("p:nth-child(2").innerText); ### via GitHub ```bash -my_ver="v2.1.2" +my_ver="v3.0.0" mkdir ./vendor/ + curl -fsSL "https://raw.githubusercontent.com/coolaj86/ajquery.js/${my_ver}/ajquery.js" \ -o ./vendor/ajquery.js + +# Lighthouse-optimized +npx -p uglify-js@3 uglifyjs ./vendor/ajquery.js -o ./vendor/ajquery.min.js ``` ```html @@ -32,7 +36,41 @@ curl -fsSL "https://raw.githubusercontent.com/coolaj86/ajquery.js/${my_ver}/ajqu ### via CDN ```html - + +``` + +Bundler-optimized: + +```html + +``` + +Tree-shaking-optimized: + +```html + +``` + +### via NPM + +```sh +npm install --save ajquery@3 +``` + +#### CommonJS + +```js +let AJQuery = require("ajquery"); +let $ = AJQuery.$; +let $$ = AJQuery.$$; +``` + +#### ESM + +```js +import AJQuery from "ajquery"; +let $ = AJQuery.$; +let $$ = AJQuery.$$; ``` ## API diff --git a/ajquery.cjs b/ajquery.cjs new file mode 100644 index 0000000..a80d3a2 --- /dev/null +++ b/ajquery.cjs @@ -0,0 +1,47 @@ +/** + * @typedef AJQuery + * @prop {AJQuerySelector} $ + * @prop {AJQuerySelectorAll} $$ + */ + +/** + * Select first matching element, just like console $ + * @callback AJQuerySelector + * @param {String} cssSelector + * @param {ParentNode} [$parent=document] + */ + +/** + * Select all matching child elements as a JS Array, just like console $$ + * @callback AJQuerySelectorAll + * @param {String} cssSelector + * @param {ParentNode} [$parent=document] + */ + +/** @type {AJQuery} */ +//@ts-ignore +var AJQuery = ("object" === typeof module && exports) || {}; +(function (window, AJQuery) { + "use strict"; + + /** @type {AJQuerySelector} */ + AJQuery.$ = function (cssSelector, $parent = document) { + let $child = $parent.querySelector(cssSelector); + return $child; + }; + + /** @type {AJQuerySelectorAll} */ + AJQuery.$$ = function (cssSelector, $parent = document) { + let nodeList = $parent.querySelectorAll(cssSelector); + let $children = Array.from(nodeList); + return $children; + }; + + Object.assign(window, AJQuery); + + //@ts-ignore + window.AJQuery = AJQuery; +})(globalThis.window || {}, AJQuery); +if ("object" === typeof module) { + module.exports = AJQuery; +} diff --git a/ajquery.mjs b/ajquery.mjs new file mode 100644 index 0000000..617efe4 --- /dev/null +++ b/ajquery.mjs @@ -0,0 +1,32 @@ +/** @import('typed-query-selector/strict') */ + +let AJQuery = { $, $$ }; + +/** + * AJQuery - The fastest, most lightweight, least dependency jQuery alternative, + * now Ai-enhanced, and better than ever! + * @namespace AJQuery + */ + +/** + * Selects the first element that matches the given selector within the specified parent. + * @param {string} sel - The CSS selector to match. + * @param {Document|Element} [$parent=document] - The parent element to search within. Defaults to document. + */ +function $(sel, $parent = document) { + let $child = $parent.querySelector(sel); + return $child; +} + +/** + * Select all matching child elements from $parent (which is document by default) + * @param {String} sel - The CSS selector to match. + * @param {Document|Element} [$parent=document] - The parent element to search within. Defaults to document. + */ +function $$(sel, $parent = document) { + let $children = $parent.querySelectorAll(sel); + let children = Array.from($children); + return children; +} + +export default AJQuery; diff --git a/example.html b/example.html index 6e4902b..cc0d13a 100644 --- a/example.html +++ b/example.html @@ -9,4 +9,15 @@ let text = $("body").textContent; console.log(text); + + + + + + diff --git a/package.json b/package.json index 59e3660..93998c0 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,31 @@ "name": "ajquery", "version": "2.1.2", "description": "The fastest, most lightweight, least dependency jQuery alternative", - "main": "ajquery.min.js", + "main": "ajquery.cjs", + "module": "ajquery.mjs", + "type": "commonjs", + "browser": { + "ajquery.min.cjs": "ajquery.min.js" + }, + "exports": { + ".": { + "require": "./ajquery.cjs", + "import": "./ajquery.mjs", + "default": "./ajquery.cjs" + } + }, "files": [ - "ajquery.js" + "ajquery.js", + "ajquery.min.js", + "ajquery.cjs", + "ajquery.min.cjs", + "ajquery.mjs", + "ajquery.min.mjs" ], "scripts": { "benchmark": "node benchmark.js", "prepare": "npm run build", - "start": "open example.html", + "start": "open http://localhost/example.html && caddy file-server --browse --root .", "prettier": "npx prettier -w '**/*.{js,md,css,html}'", "build": "npx uglify-js ajquery.js -o ajquery.min.js", "test": "node test.js" From 1ee66ed697671f52a6ff247e40f2c192fd295772 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 14:43:03 -0600 Subject: [PATCH 06/12] chore: add ci config --- .github/workflows/node.js.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..1e042af --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,24 @@ +name: Node.js CI +on: + push: + branches: ['main'] + pull_request: +jobs: + build: + name: 'Node.js build: fmt, clean-install, lint, test' + runs-on: ubuntu-latest + strategy: + matrix: + node-version: + # - 20.x + - latest + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: npm run fmt + - run: npm clean-install + - run: npm run lint + - run: npm run test From 480227cc4f396b14b1c3895237768f462184a95f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 14:42:04 -0600 Subject: [PATCH 07/12] chore: add tooling config --- jsconfig.json | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 ++++++-- 2 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 jsconfig.json diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..1ea57c0 --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,118 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + "typeRoots": ["./typings","./node_modules/@types"], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ + // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "include": [ + "ajquery.js", + "ajquery.cjs", + "ajquery.mjs", + "bin/**/*.js", + "lib/**/*.js", + "src/**/*.js" + ], + "exclude": ["node_modules"] +} diff --git a/package.json b/package.json index 93998c0..035d43d 100644 --- a/package.json +++ b/package.json @@ -24,12 +24,21 @@ "ajquery.min.mjs" ], "scripts": { - "benchmark": "node benchmark.js", - "prepare": "npm run build", + "benchmark": "node ./benchmark.js", + "build": "npm run build-all", + "bump": "npm version -m \"chore(release): bump to v%s\"", + "fmt": "npm run prettier", + "lint": "npm run jshint && npm run tsc", "start": "open http://localhost/example.html && caddy file-server --browse --root .", + "test": "node ./tests/", + "--------": "---------------------------------------", + "build-all": "npx uglify-js ajquery.js -o ajquery.min.js && npx uglify-js ajquery.cjs -o ajquery.min.cjs && npx uglify-js ajquery.js -o ajquery.min.mjs", + "jshint": "npx -p jshint@2.x -- jshint -c ./.jshintrc ./ajquery.js ./ajquery.cjs ./ajquery.mjs", + "prepare": "npm run build", + "prepublish": "npm run reexport-types", "prettier": "npx prettier -w '**/*.{js,md,css,html}'", - "build": "npx uglify-js ajquery.js -o ajquery.min.js", - "test": "node test.js" + "reexport-types": "npx -p jswt@1.x -- reexport", + "tsc": "npx -p typescript@5.x -- tsc -p ./jsconfig.json" }, "repository": { "type": "git", From cef7e822eb47d35b4364e49a55eac3117826b813 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 16:50:21 -0600 Subject: [PATCH 08/12] test: add test runner --- test.js => tests/browser.js | 0 tests/index.js | 109 ++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) rename test.js => tests/browser.js (100%) create mode 100644 tests/index.js diff --git a/test.js b/tests/browser.js similarity index 100% rename from test.js rename to tests/browser.js diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..86f5731 --- /dev/null +++ b/tests/index.js @@ -0,0 +1,109 @@ +"use strict"; + +let ChildProcess = require("child_process"); +let Fs = require("node:fs/promises"); +let Path = require("node:path"); + +async function main() { + console.info("TAP version 13"); + + let dirents = await Fs.readdir(__dirname, { withFileTypes: true }); + + let failures = 0; + let count = 0; + for (let dirent of dirents) { + if (dirent.name === "index.js") { + continue; + } + + count += 1; + let direntPath = Path.join(__dirname, dirent.name); + let relPath = Path.relative(".", direntPath); + + let success = await handleEach(count, relPath); + if (!success) { + failures += 1; + } + } + + let start = 1; + if (count < 1) { + start = 0; + } + + let passes = count - failures; + console.info(``); + console.info(`${start}..${count}`); + console.info(`# tests ${count}`); + console.info(`# pass ${passes}`); + console.info(`# fail ${failures}`); + console.info(`# skip 0`); + + if (failures !== 0) { + process.exit(1); + } +} + +async function handleEach(count, relPath) { + let success = await exec("node", [relPath]) + .then(function (result) { + console.info(`ok ${count} - ${relPath}`); + return true; + }) + .catch(function (err) { + console.info(`not ok ${count} - ${relPath}`); + if (err.code) { + console.info(` # Error: ${err.code}`); + } + if (err.stderr) { + console.info(` # Stderr: ${err.stderr}`); + } + return false; + }); + + return success; +} + +async function exec(exe, args) { + return new Promise(function (resolve, reject) { + let cmd = ChildProcess.spawn(exe, args); + + let stdout = []; + let stderr = []; + + cmd.stdout.on("data", function (data) { + stdout.push(data.toString("utf8")); + }); + + cmd.stderr.on("data", function (data) { + stderr.push(data.toString("utf8")); + }); + + cmd.on("close", function (code) { + let result = { + code: code, + stdout: stdout.join(""), + stderr: stderr.join(""), + }; + + if (!code) { + resolve(result); + return; + } + + let err = new Error(result.stderr); + Object.assign(err, result); + reject(err); + }); + }); +} + +main() + .then(function () { + process.exit(0); + }) + .catch(function (err) { + console.error("Fail:"); + console.error(err.stack || err); + process.exit(1); + }); From b47f4eeb313903b9899b555cd06b41e200ccc694 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 17:00:20 -0600 Subject: [PATCH 09/12] test: commonjs can be required --- tests/commonjs.cjs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/commonjs.cjs diff --git a/tests/commonjs.cjs b/tests/commonjs.cjs new file mode 100644 index 0000000..c400d45 --- /dev/null +++ b/tests/commonjs.cjs @@ -0,0 +1,21 @@ +"use strict"; + +let AJQueryDefault = require("../"); +let AJQueryExplicit = require("../ajquery.cjs"); + +if (!AJQueryDefault.$) { + throw new Error("did not export $ correctly"); +} +if (!AJQueryDefault.$$) { + throw new Error("did not export $$ correctly"); +} + +if (AJQueryDefault.$ !== AJQueryExplicit.$) { + throw new Error("exported $s do not match"); +} + +if (AJQueryDefault.$$ !== AJQueryExplicit.$$) { + throw new Error("exported $$s do not match"); +} + +console.log(`\x1b[34mPASS\x1b[33m`); From 9f3017b2e947b65c4090505627f759b6d89a895e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 17:00:30 -0600 Subject: [PATCH 10/12] test: esm can be imported --- tests/esm.mjs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/esm.mjs diff --git a/tests/esm.mjs b/tests/esm.mjs new file mode 100644 index 0000000..70ab827 --- /dev/null +++ b/tests/esm.mjs @@ -0,0 +1,12 @@ +"use strict"; + +import AJQueryExplicit from "../ajquery.mjs"; + +if (!AJQueryExplicit.$) { + throw new Error("did not export $ correctly"); +} +if (!AJQueryExplicit.$$) { + throw new Error("did not export $$ correctly"); +} + +console.log(`\x1b[34mPASS\x1b[33m`); From 738922451e11ed5b39c18164322a83673eaefbf4 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 16:46:55 -0600 Subject: [PATCH 11/12] chore: add Vite benchmark --- benchmark.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/benchmark.js b/benchmark.js index d6a71d4..58a1710 100644 --- a/benchmark.js +++ b/benchmark.js @@ -8,6 +8,8 @@ async function main() { console.info("Angular: 2517"); await sleep(520); console.info("React: 3785"); + await sleep(128); + console.info("Vite: 6666"); await sleep(230); console.info('"Vanilla" JS: 6237'); await sleep(65); From 0635d41907c33d1830c64a3fb98594a3b3037ddd Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 29 Aug 2024 18:11:16 -0600 Subject: [PATCH 12/12] chore(release): bump to v3.0.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0202445..07e3268 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ajquery", - "version": "2.1.2", + "version": "3.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ajquery", - "version": "2.1.2", + "version": "3.0.0", "license": "MPL-2.0" } } diff --git a/package.json b/package.json index 035d43d..39d07ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ajquery", - "version": "2.1.2", + "version": "3.0.0", "description": "The fastest, most lightweight, least dependency jQuery alternative", "main": "ajquery.cjs", "module": "ajquery.mjs",