pax_global_header00006660000000000000000000000064145776463040014532gustar00rootroot0000000000000052 comment=d4afc77d45bae5de6aca01bf9628c839eeb2f903 gulpjs-sparkles-d4afc77/000077500000000000000000000000001457764630400153615ustar00rootroot00000000000000gulpjs-sparkles-d4afc77/.editorconfig000066400000000000000000000003261457764630400200370ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true end_of_line = lf [*.md] trim_trailing_whitespace = false gulpjs-sparkles-d4afc77/.eslintignore000066400000000000000000000000121457764630400200550ustar00rootroot00000000000000coverage/ gulpjs-sparkles-d4afc77/.eslintrc000066400000000000000000000000301457764630400171760ustar00rootroot00000000000000{ "extends": "gulp" } gulpjs-sparkles-d4afc77/.gitattributes000066400000000000000000000000161457764630400202510ustar00rootroot00000000000000* text eol=lf gulpjs-sparkles-d4afc77/.github/000077500000000000000000000000001457764630400167215ustar00rootroot00000000000000gulpjs-sparkles-d4afc77/.github/workflows/000077500000000000000000000000001457764630400207565ustar00rootroot00000000000000gulpjs-sparkles-d4afc77/.github/workflows/dev.yml000066400000000000000000000031051457764630400222560ustar00rootroot00000000000000name: dev on: pull_request: push: branches: - master - main env: CI: true jobs: prettier: name: Format code runs-on: ubuntu-latest if: ${{ github.event_name == 'push' }} steps: - name: Checkout uses: actions/checkout@v2 - name: Prettier uses: gulpjs/prettier_action@v3.0 with: commit_message: 'chore: Run prettier' prettier_options: '--write .' test: name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: node: [10, 12, 14, 16] os: [ubuntu-latest, windows-latest, macos-latest] steps: - name: Clone repository uses: actions/checkout@v2 - name: Set Node.js version uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} - run: node --version - run: npm --version - name: Install npm dependencies run: npm install - name: Run lint run: npm run lint - name: Run tests run: npm test - name: Coveralls uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: ${{matrix.os}}-node-${{ matrix.node }} parallel: true coveralls: needs: test name: Finish up runs-on: ubuntu-latest steps: - name: Coveralls Finished uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} parallel-finished: true gulpjs-sparkles-d4afc77/.github/workflows/release.yml000066400000000000000000000005511457764630400231220ustar00rootroot00000000000000name: release on: push: branches: - master - main jobs: release-please: runs-on: ubuntu-latest steps: - uses: GoogleCloudPlatform/release-please-action@v2 with: token: ${{ secrets.GITHUB_TOKEN }} release-type: node package-name: release-please-action bump-minor-pre-major: true gulpjs-sparkles-d4afc77/.gitignore000066400000000000000000000017111457764630400173510ustar00rootroot00000000000000# Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # TypeScript v1 declaration files typings/ # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env # next.js build output .next # Garbage files .DS_Store # Test results test.xunit gulpjs-sparkles-d4afc77/.npmrc000066400000000000000000000000231457764630400164740ustar00rootroot00000000000000package-lock=false gulpjs-sparkles-d4afc77/.prettierignore000066400000000000000000000000441457764630400204220ustar00rootroot00000000000000coverage/ .nyc_output/ CHANGELOG.md gulpjs-sparkles-d4afc77/CHANGELOG.md000066400000000000000000000025751457764630400172030ustar00rootroot00000000000000# Changelog ## [2.1.0](https://www.github.com/gulpjs/sparkles/compare/v2.0.0...v2.1.0) (2024-03-23) ### Features * Add module for accessing legacy store ([#10](https://www.github.com/gulpjs/sparkles/issues/10)) ([7f8b667](https://www.github.com/gulpjs/sparkles/commit/7f8b6678fe3ec8449f47eb156b91ce5150ed9348)) ## [2.0.0](https://www.github.com/gulpjs/sparkles/compare/v1.0.1...v2.0.0) (2022-02-01) ### ⚠ BREAKING CHANGES * Use a Symbol for attaching the default namespace to the store * Use a Symbol for attaching the store to the global (#9) * Normalize repository, dropping node <10.13 support (#6) ### Features * Use a Symbol for attaching the default namespace to the store ([2196fb1](https://www.github.com/gulpjs/sparkles/commit/2196fb1503f14f02c9422566d1e3635aa93e6ac0)) * Use a Symbol for attaching the store to the global ([#9](https://www.github.com/gulpjs/sparkles/issues/9)) ([2196fb1](https://www.github.com/gulpjs/sparkles/commit/2196fb1503f14f02c9422566d1e3635aa93e6ac0)) * Use Symbol.for so other applications can create the same Symbol ([2196fb1](https://www.github.com/gulpjs/sparkles/commit/2196fb1503f14f02c9422566d1e3635aa93e6ac0)) ### Miscellaneous Chores * Normalize repository, dropping node <10.13 support ([#6](https://www.github.com/gulpjs/sparkles/issues/6)) ([6d6f7a8](https://www.github.com/gulpjs/sparkles/commit/6d6f7a8633a437c474efb8a1768b3617f0f8e87d)) gulpjs-sparkles-d4afc77/LICENSE000066400000000000000000000022171457764630400163700ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2015, 2018-2019, 2021 Blaine Bublitz and Eric Schoffstall 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. gulpjs-sparkles-d4afc77/README.md000066400000000000000000000037341457764630400166470ustar00rootroot00000000000000

# sparkles [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] Namespaced global event emitter ## Usage Sparkles exports a function that returns a singleton `EventEmitter`. This EE can be shared across your application, whether or not node loads multiple copies. Note: If you put an event handler in a file in your application, that file must be loaded in via an import somewhere in your application, even if it's not directly being used. Otherwise, it will not be loaded into memory. ```js var sparkles = require('sparkles')(); // make sure to call the function sparkles.on('my-event', function (evt) { console.log('my-event handled', evt); }); sparkles.emit('my-event', { my: 'event' }); ``` ## API ### sparkles(namespace) Returns an EventEmitter that is shared amongst the provided namespace. If no namespace is provided, returns a default EventEmitter. ### sparkles.exists(namespace); Checks whether a namespace exists and returns true or false. ## Why the name? This is a "global emitter"; shortened: "glitter" but it was already taken; so we got sparkles instead :smile: ## License MIT [downloads-image]: https://img.shields.io/npm/dm/sparkles.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/sparkles [npm-image]: https://img.shields.io/npm/v/sparkles.svg?style=flat-square [ci-url]: https://github.com/gulpjs/sparkles/actions?query=workflow:dev [ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/sparkles/dev.yml?branch=master&style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/sparkles [coveralls-image]: https://img.shields.io/coveralls/gulpjs/sparkles/master.svg?style=flat-square gulpjs-sparkles-d4afc77/index.js000066400000000000000000000014721457764630400170320ustar00rootroot00000000000000'use strict'; var EventEmitter = require('events').EventEmitter; var sparklesNamespace = Symbol.for('sparkles:store'); var defaultNamespace = Symbol.for('sparkles:namespace'); function getStore() { var store = global[sparklesNamespace]; if (!store) { store = global[sparklesNamespace] = {}; } return store; } function getEmitter(namespace) { var store = getStore(); namespace = namespace || defaultNamespace; var ee = store[namespace]; if (!ee) { ee = store[namespace] = new EventEmitter(); ee.setMaxListeners(0); ee.remove = function remove() { ee.removeAllListeners(); delete store[namespace]; }; } return ee; } function exists(namespace) { var store = getStore(); return !!store[namespace]; } module.exports = getEmitter; module.exports.exists = exists; gulpjs-sparkles-d4afc77/legacy.js000066400000000000000000000015721457764630400171700ustar00rootroot00000000000000'use strict'; var EventEmitter = require('events').EventEmitter; var sparklesNamespace = 'store@sparkles'; var defaultNamespace = 'default' function getStore() { var store = global[sparklesNamespace]; if (!store) { Object.defineProperty(global, sparklesNamespace, { value: {}, enumerable: false, }); store = global[sparklesNamespace]; } return store; } function getEmitter(namespace) { var store = getStore(); namespace = namespace || defaultNamespace; var ee = store[namespace]; if (!ee) { ee = store[namespace] = new EventEmitter(); ee.setMaxListeners(0); ee.remove = function remove() { ee.removeAllListeners(); delete store[namespace]; }; } return ee; } function exists(namespace) { var store = getStore(); return !!store[namespace]; } module.exports = getEmitter; module.exports.exists = exists; gulpjs-sparkles-d4afc77/package.json000066400000000000000000000016551457764630400176560ustar00rootroot00000000000000{ "name": "sparkles", "version": "2.1.0", "description": "Namespaced global event emitter", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Blaine Bublitz " ], "repository": "gulpjs/sparkles", "license": "MIT", "engines": { "node": ">= 10.13.0" }, "main": "index.js", "files": [ "LICENSE", "index.js", "legacy.js" ], "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "nyc mocha --async-only" }, "devDependencies": { "eslint": "^7.32.0", "eslint-config-gulp": "^5.0.1", "eslint-plugin-node": "^11.1.0", "expect": "^27.3.1", "mocha": "^8.4.0", "nyc": "^15.1.0" }, "nyc": { "reporter": [ "lcov", "text-summary" ] }, "prettier": { "singleQuote": true }, "keywords": [ "ee", "emitter", "events", "global", "namespaced" ] } gulpjs-sparkles-d4afc77/test/000077500000000000000000000000001457764630400163405ustar00rootroot00000000000000gulpjs-sparkles-d4afc77/test/index.js000066400000000000000000000062641457764630400200150ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var EventEmitter = require('events').EventEmitter; var sparkles = require('../'); describe('sparkles()', function () { describe('behavior on global', function () { var ee; var storeSymbol = Symbol.for('sparkles:store'); var namespaceSymbol = Symbol.for('sparkles:namespace'); beforeEach(function (done) { ee = sparkles(); done(); }); afterEach(function (done) { ee.remove(); done(); }); it('will attach the sparkles store namespace to global', function (done) { expect(global[storeSymbol]).toBeTruthy(); done(); }); it('will attach an event emitter to the sparkles store default namespace', function (done) { expect(global[storeSymbol][namespaceSymbol]).toBeInstanceOf(EventEmitter); done(); }); it('removes the event emitter from the store when remove is called', function (done) { ee.on('test', function () {}); ee.remove(); expect(global[storeSymbol][namespaceSymbol]).toBeUndefined(); done(); }); it('does not show up when enumerating the global object', function (done) { expect(Object.keys(global)).not.toContain(storeSymbol); done(); }); }); it('should get the default emitter if namespace is not specified', function (done) { var ee = sparkles(); expect(ee).toBeInstanceOf(EventEmitter); expect(sparkles()).toBe(ee); done(); }); it('should get an emitter for a specified namespace', function (done) { var ee = sparkles('ns1'); expect(ee).toBeInstanceOf(EventEmitter); expect(sparkles()).not.toBe(ee); expect(sparkles('ns1')).toBe(ee); expect(sparkles('ns2')).not.toBe(ee); done(); }); it('should remove and re-create emitter in the store', function (done) { var ee0 = sparkles(); var ee1 = sparkles('ns1'); ee0.remove(); expect(sparkles()).not.toBe(ee0); expect(sparkles('ns1')).toBe(ee1); ee1.remove(); expect(sparkles('ns1')).not.toBe(ee1); done(); }); }); describe('sparkles.exists()', function () { it('checks if a namespace has been defined', function (done) { expect(sparkles.exists('test')).toBe(false); var ee = sparkles('test'); expect(sparkles.exists('test')).toBe(true); ee.remove(); expect(sparkles.exists('test')).toBe(false); done(); }); }); describe('namespace', function () { var storeSymbol = Symbol.for('sparkles:store'); var namespaceSymbol = Symbol.for('sparkles:namespace'); beforeEach(function (done) { global[storeSymbol] = {}; done(); }); afterEach(function (done) { delete global[storeSymbol]; done(); }); it('should use an EE from sparkles namespace if it already exists', function (done) { var ee = (global[storeSymbol][namespaceSymbol] = new EventEmitter()); ee.custom = 'ee'; var sparkles = require('../')(); expect(sparkles.custom).toEqual('ee'); done(); }); it('should allow custom namespaces', function (done) { var ee = (global[storeSymbol].customNamespace = new EventEmitter()); ee.custom = true; var sparkles = require('../')('customNamespace'); expect(sparkles.custom).toEqual(true); done(); }); }); gulpjs-sparkles-d4afc77/test/legacy.js000066400000000000000000000063251457764630400201500ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var EventEmitter = require('events').EventEmitter; var sparkles = require('../legacy.js'); describe('legacy: sparkles()', function () { describe('behavior on global', function () { var ee; var storeNamespace = 'store@sparkles'; var defaultNamespace = 'default'; beforeEach(function (done) { ee = sparkles(); done(); }); afterEach(function (done) { ee.remove(); done(); }); it('will attach the sparkles store namespace to global', function (done) { expect(global[storeNamespace]).toBeTruthy(); done(); }); it('will attach an event emitter to the sparkles store default namespace', function (done) { expect(global[storeNamespace][defaultNamespace]).toBeInstanceOf(EventEmitter); done(); }); it('removes the event emitter from the store when remove is called', function (done) { ee.on('test', function () {}); ee.remove(); expect(global[storeNamespace][defaultNamespace]).toBeUndefined(); done(); }); it('does not show up when enumerating the global object', function (done) { expect(Object.keys(global)).not.toContain(storeNamespace); done(); }); }); it('should get the default emitter if namespace is not specified', function (done) { var ee = sparkles(); expect(ee).toBeInstanceOf(EventEmitter); expect(sparkles()).toBe(ee); done(); }); it('should get an emitter for a specified namespace', function (done) { var ee = sparkles('ns1'); expect(ee).toBeInstanceOf(EventEmitter); expect(sparkles()).not.toBe(ee); expect(sparkles('ns1')).toBe(ee); expect(sparkles('ns2')).not.toBe(ee); done(); }); it('should remove and re-create emitter in the store', function (done) { var ee0 = sparkles(); var ee1 = sparkles('ns1'); ee0.remove(); expect(sparkles()).not.toBe(ee0); expect(sparkles('ns1')).toBe(ee1); ee1.remove(); expect(sparkles('ns1')).not.toBe(ee1); done(); }); }); describe('legacy: sparkles.exists()', function () { it('checks if a namespace has been defined', function (done) { expect(sparkles.exists('test')).toBe(false); var ee = sparkles('test'); expect(sparkles.exists('test')).toBe(true); ee.remove(); expect(sparkles.exists('test')).toBe(false); done(); }); }); describe('legacy: namespace', function () { var storeNamespace = Symbol.for('sparkles:store'); var defaultNamespace = Symbol.for('sparkles:namespace'); beforeEach(function (done) { global[storeNamespace] = {}; done(); }); afterEach(function (done) { delete global[storeNamespace]; done(); }); it('should use an EE from sparkles namespace if it already exists', function (done) { var ee = (global[storeNamespace][defaultNamespace] = new EventEmitter()); ee.custom = 'ee'; var sparkles = require('../')(); expect(sparkles.custom).toEqual('ee'); done(); }); it('should allow custom namespaces', function (done) { var ee = (global[storeNamespace].customNamespace = new EventEmitter()); ee.custom = true; var sparkles = require('../')('customNamespace'); expect(sparkles.custom).toEqual(true); done(); }); });