Wednesday, 1 December 2021

after rollup build: regeneratorRuntime is not defined

I have the following rollup.config.js:

// Import rollup plugins
import html from '@web/rollup-plugin-html';
import polyfillsLoader from '@web/rollup-plugin-polyfills-loader';
import {copy} from '@web/rollup-plugin-copy';
import resolve from '@rollup/plugin-node-resolve';
import {getBabelOutputPlugin} from '@rollup/plugin-babel';
import {terser} from 'rollup-plugin-terser';
import minifyHTML from 'rollup-plugin-minify-html-literals';
import summary from 'rollup-plugin-summary';

// Configure an instance of @web/rollup-plugin-html
const htmlPlugin = html({
  rootDir: './',
  flattenOutput: false,
});

export default {
  // Entry point for application build; can specify a glob to build multiple
  // HTML files for non-SPA app
  input: 'index.html',
  plugins: [
    htmlPlugin,
    // Resolve bare module specifiers to relative paths
    resolve(),
    // Minify HTML template literals
    minifyHTML(),
    // Minify JS
    terser({
      module: true,
      warnings: true,
    }),
    // Inject polyfills into HTML (core-js, regnerator-runtime, webcoponents,
    // lit/polyfill-support) and dynamically loads modern vs. legacy builds
    polyfillsLoader({
      modernOutput: {
        name: 'modern',
      },
      // Feature detection for loading legacy bundles
      legacyOutput: {
        name: 'legacy',
        test: '!!Array.prototype.flat',
        type: 'systemjs',
      },
      // List of polyfills to inject (each has individual feature detection)
      polyfills: {
        hash: true,
        coreJs: true,
        regeneratorRuntime: true,
        fetch: true,
        webcomponents: true,
        // Custom configuration for loading Lit's polyfill-support module,
        // required for interfacing with the webcomponents polyfills
        custom: [
          {
            name: 'lit-polyfill-support',
            path: 'node_modules/lit/polyfill-support.js',
            test: "!('attachShadow' in Element.prototype)",
            module: false,
          },
        ],
      },
    }),
    // Print bundle summary
    summary(),
    // Optional: copy any static assets to build directory
    copy({
      patterns: ['data/**/*', 'images/**/*'],
    }),
  ],
  // Specifies two JS output configurations, modern and legacy, which the HTML plugin will
  // automatically choose between; the legacy build is compiled to ES5
  // and SystemJS modules
  output: [
    {
      // Modern JS bundles (no JS compilation, ES module output)
      format: 'esm',
      chunkFileNames: '[name]-[hash].js',
      entryFileNames: '[name]-[hash].js',
      dir: 'build',
      plugins: [htmlPlugin.api.addOutput('modern')],
    },
    {
      // Legacy JS bundles (ES5 compilation and SystemJS module output)
      format: 'esm',
      chunkFileNames: 'legacy-[name]-[hash].js',
      entryFileNames: 'legacy-[name]-[hash].js',
      dir: 'build',
      plugins: [
        htmlPlugin.api.addOutput('legacy'),
        // Uses babel to compile JS to ES5 and modules to SystemJS
        getBabelOutputPlugin({
          compact: true,
          presets: [
            [
              '@babel/preset-env',
              {
                targets: {
                  ie: '11',
                },
                modules: 'systemjs',
              },
            ],
          ],
        }),
      ],
    },
  ],
  preserveEntrySignatures: false,
};

The build it self runs successfully however when trying to access the site no matter which browser I use I keep getting:

Uncaught (in promise) ReferenceError: regeneratorRuntime is not defined

Can anyone tell me what I've done wrong?



from after rollup build: regeneratorRuntime is not defined

NPM Error "Can't find Python executable" in MacOS Big Sur

I've been looking for the answer to this for a good solid week now, with no success. I've looked at every StackOverflow post, every article from Google and every related Github issue I could find. Most related errors seem to be older, so I'm wondering if my issue is slightly different due to me being on macOS Big Sur.

The issue: When I try to run yarn install in my local repo, I receive an error related to node-gyp and a python executable that is unable to be found. Here is what my terminal shows:

yarn install v1.22.17

...other stuff

[4/4] 🔨  Building fresh packages...
[6/13] ⠐ node-sass
[2/13] ⠐ node-sass
[10/13] ⠐ metrohash
[4/13] ⠐ fsevents
error /Users/jimmiejackson/Documents/repositories/repo-name/node_modules/metrohash: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /Users/jimmiejackson/Documents/repositories/repo-name/node_modules/metrohash
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@12.18.0 | darwin | x64
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "/usr/local/opt/python@3.9/bin/python3", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (/Users/jimmiejackson/Documents/repositories/repo-name/node_modules/node-gyp/lib/configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/Users/jimmiejackson/Documents/repositories/repo-name/node_modules/node-gyp/lib/configure.js:406:16)
gyp ERR! stack     at F (/Users/jimmiejackson/Documents/repositories/repo-name/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/Users/jimmiejackson/Documents/repositories/repo-name/node_modules/which/which.js:80:29)
gyp ERR! stack     at /Users/jimmiejackson/Documents/repositories/repo-name/node_modules/which/which.js:89:16
gyp ERR! stack     at /Users/jimmiejackson/Documents/repositories/repo-name/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /Users/jimmiejackson/Documents/repositories/repo-name/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:167:21)
gyp ERR! System Darwin 20.6.0
gyp ERR! command "/Users/jimmiejackson/.nvm/versions/node/v12.18.0/bin/node" "/Users/jimmiejackson/Documents/repositories/repo-name/node_modules/metrohash/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/jimmiejackson/Documents/repositories/repo-name/node_modules/metrohash

I'm not entirely sure what this error means or why this node module is searching for python3. I've tried running npm set config /path/to/python, downloading python3, setting the PYTHON path in my .zshrc profile, but nothing seems to be working. It's entirely possible that my lack of understanding of the issue means that I'm on the right path but didn't quite get something right. Any ideas?



from NPM Error "Can't find Python executable" in MacOS Big Sur

Collapsible subset of partially ordered set

Problem

I am looking for python implementation of a special kind of subset of a partially ordered universal set. It is special because there are restrictions on which elements from the universal set this subset (which I would call CollapsibleSubset) can contain. CollapsibleSubset has to satisfy 1) "Collapsibility" and 2) "Absence of comparable elements" requirements. The operations on CollapsibleSubsets are also defined differently compared to normal sets. I will illustrate the formal definition with the example of file system paths.

Example - File system paths set

Consider a file system tree:

/root/
├── dir1/
│   ├── file11.txt
│   └── file12.txt
├── dir2/
│   ├── file21.txt
│   └── file22.txt
└── file0.txt

The universal set, in this case, are all valid paths { /root, /root/dir1, /root/dir1/file11.txt .. /root/file0.txt}. The partial order lt is defined by the directory structure, i.e. lt(a,b) means that b is an ancestor directory of a, e.g. lt(/root/dir1, /root) is True.

The idea of using CollapsibleSubset is to represent a set of paths in the briefest way, i.e. with a few elements as possible. E.g. CollapsibleSubset({/root/dir1, /root/dir2}) would represent all files and dirs in dir1, dir2.

Definition

CollapibleSubset A of a partially-ordered set U, is a set of elements from U that satisfies two requirements:

  1. "Collapsibility".

    , where dp is a direct predecessor relation:

    In other words, if all predecessors of an element belong to the subset, then the element itself must belong to the subset.

    Example. {root/dir1/file11.txt, /root/dir1/file12.txt} is not a valid CollapibleSubset, but {/root/dir1} is.

  2. No comparable elements

    In other words, if an element belongs to the subset, none of its predecessors can.

    Example. {/root/dir1, /root/dir1/file12.txt} is not a valid CollapibleSubset, but {/root/dir1} is.

Requirements 1 and 2 ensure that the subset contains as few elements as possible.

Operations

Union

A,B - CollapsibleSubsets, C=Union(A,B) if C is a valid CollapsibleSubset and:

Example.

CollapsibleSubset({'/root/dir1', '/root/dir2/file21.txt'}).union(
    CollapsibleSubset({'/root/dir2/file22.txt', '/root/file0.txt'}
) = CollapsibleSubset({'/root'})

Complement

A - CollapsibleSubset, B = Complement(A) if B is a valid CollapsibleSubset and:

Example.

CollapsibleSubset({'/root/dir2/file21.txt'}).complement()=
CollapsibleSubset({'/root/dir1', '/root/dir2/file22.txt', '/root/file0.txt'}))

Possible CollapsibleSubset creation API

Partial order in practice can be specified by supremum and a function that returns direct predecessors. For the paths set example:

>>> colsub = CollapsibleSubset(sup='/root', pred_func=lambda p: os.listdir(p), elements={'/root/dir1', '/root/file0'})

Another use-case - arbitrary hierarchy subset

The file system example is not my only use-case for which having a CollapsibleSubset class would be useful. Another one is defining a subset of an arbitrary hierarchy in the fastest way.

Example. Having the following hierarchy:

                Commit
             /     |    \
           /      Fix     \
         /       /   \      \
  Feature   CodeFix  DocFix  Refactoring
   /          /        \           \
 ....       ....       ....        ...

defined as a dictionary:

>>> hierarchy = {'Commit': ['Feature', 'Fix', 'Refactoring'], 'Fix': ['CodeFix', 'DocFix'], ...}

I would like to define a subset of it in the briefest way. For example, a way to define all types of commits that are different kinds of fixes or refactorings with CollapsibleSubset would be:

>>> CollapsibleSubset('Commit', lambda p: hierarchy[p], {'Fix', 'Refatoring'})

Question

Is such CollapsibleSubset abstraction already implemented in any library?



from Collapsible subset of partially ordered set