@quilted/rollup 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +1 -0
  3. package/build/cjs/app.cjs +137 -0
  4. package/build/cjs/constants.cjs +13 -0
  5. package/build/cjs/env.cjs +130 -0
  6. package/build/cjs/index.cjs +16 -0
  7. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/TemplateTag/TemplateTag.cjs +168 -0
  8. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaLists/commaLists.cjs +8 -0
  9. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsAnd/commaListsAnd.cjs +8 -0
  10. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsOr/commaListsOr.cjs +8 -0
  11. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/html/html.cjs +10 -0
  12. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineArrayTransformer/inlineArrayTransformer.cjs +48 -0
  13. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineLists/inlineLists.cjs +8 -0
  14. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLine/oneLine.cjs +7 -0
  15. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaLists/oneLineCommaLists.cjs +8 -0
  16. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsAnd/oneLineCommaListsAnd.cjs +8 -0
  17. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsOr/oneLineCommaListsOr.cjs +8 -0
  18. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineInlineLists/oneLineInlineLists.cjs +8 -0
  19. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineTrim/oneLineTrim.cjs +7 -0
  20. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/removeNonPrintingValuesTransformer/removeNonPrintingValuesTransformer.cjs +23 -0
  21. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceResultTransformer/replaceResultTransformer.cjs +22 -0
  22. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceSubstitutionTransformer/replaceSubstitutionTransformer.cjs +22 -0
  23. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/safeHtml/safeHtml.cjs +10 -0
  24. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/splitStringTransformer/splitStringTransformer.cjs +20 -0
  25. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndent/stripIndent.cjs +11 -0
  26. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndentTransformer/stripIndentTransformer.cjs +37 -0
  27. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndents/stripIndents.cjs +7 -0
  28. package/build/cjs/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/trimResultTransformer/trimResultTransformer.cjs +33 -0
  29. package/build/cjs/request-router.cjs +30 -0
  30. package/build/cjs/shared/magic-module.cjs +44 -0
  31. package/build/cjs/shared/strings.cjs +16 -0
  32. package/build/esm/app.mjs +130 -0
  33. package/build/esm/constants.mjs +7 -0
  34. package/build/esm/env.mjs +108 -0
  35. package/build/esm/index.mjs +3 -0
  36. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/TemplateTag/TemplateTag.mjs +164 -0
  37. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaLists/commaLists.mjs +6 -0
  38. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsAnd/commaListsAnd.mjs +6 -0
  39. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsOr/commaListsOr.mjs +6 -0
  40. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/html/html.mjs +8 -0
  41. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineArrayTransformer/inlineArrayTransformer.mjs +44 -0
  42. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineLists/inlineLists.mjs +6 -0
  43. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLine/oneLine.mjs +5 -0
  44. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaLists/oneLineCommaLists.mjs +6 -0
  45. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsAnd/oneLineCommaListsAnd.mjs +6 -0
  46. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsOr/oneLineCommaListsOr.mjs +6 -0
  47. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineInlineLists/oneLineInlineLists.mjs +6 -0
  48. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineTrim/oneLineTrim.mjs +5 -0
  49. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/removeNonPrintingValuesTransformer/removeNonPrintingValuesTransformer.mjs +19 -0
  50. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceResultTransformer/replaceResultTransformer.mjs +18 -0
  51. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceSubstitutionTransformer/replaceSubstitutionTransformer.mjs +18 -0
  52. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/safeHtml/safeHtml.mjs +8 -0
  53. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/splitStringTransformer/splitStringTransformer.mjs +16 -0
  54. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndent/stripIndent.mjs +7 -0
  55. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndentTransformer/stripIndentTransformer.mjs +33 -0
  56. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndents/stripIndents.mjs +5 -0
  57. package/build/esm/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/trimResultTransformer/trimResultTransformer.mjs +29 -0
  58. package/build/esm/request-router.mjs +28 -0
  59. package/build/esm/shared/magic-module.mjs +41 -0
  60. package/build/esm/shared/strings.mjs +14 -0
  61. package/build/esnext/app.esnext +130 -0
  62. package/build/esnext/constants.esnext +7 -0
  63. package/build/esnext/env.esnext +108 -0
  64. package/build/esnext/index.esnext +3 -0
  65. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/TemplateTag/TemplateTag.esnext +164 -0
  66. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaLists/commaLists.esnext +6 -0
  67. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsAnd/commaListsAnd.esnext +6 -0
  68. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsOr/commaListsOr.esnext +6 -0
  69. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/html/html.esnext +8 -0
  70. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineArrayTransformer/inlineArrayTransformer.esnext +44 -0
  71. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineLists/inlineLists.esnext +6 -0
  72. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLine/oneLine.esnext +5 -0
  73. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaLists/oneLineCommaLists.esnext +6 -0
  74. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsAnd/oneLineCommaListsAnd.esnext +6 -0
  75. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsOr/oneLineCommaListsOr.esnext +6 -0
  76. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineInlineLists/oneLineInlineLists.esnext +6 -0
  77. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineTrim/oneLineTrim.esnext +5 -0
  78. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/removeNonPrintingValuesTransformer/removeNonPrintingValuesTransformer.esnext +19 -0
  79. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceResultTransformer/replaceResultTransformer.esnext +18 -0
  80. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/replaceSubstitutionTransformer/replaceSubstitutionTransformer.esnext +18 -0
  81. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/safeHtml/safeHtml.esnext +8 -0
  82. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/splitStringTransformer/splitStringTransformer.esnext +16 -0
  83. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndent/stripIndent.esnext +7 -0
  84. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndentTransformer/stripIndentTransformer.esnext +33 -0
  85. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndents/stripIndents.esnext +5 -0
  86. package/build/esnext/node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/trimResultTransformer/trimResultTransformer.esnext +29 -0
  87. package/build/esnext/request-router.esnext +28 -0
  88. package/build/esnext/shared/magic-module.esnext +41 -0
  89. package/build/esnext/shared/strings.esnext +14 -0
  90. package/build/tsconfig.tsbuildinfo +1 -0
  91. package/build/typescript/app.d.ts +163 -0
  92. package/build/typescript/app.d.ts.map +1 -0
  93. package/build/typescript/constants.d.ts +6 -0
  94. package/build/typescript/constants.d.ts.map +1 -0
  95. package/build/typescript/env.d.ts +51 -0
  96. package/build/typescript/env.d.ts.map +1 -0
  97. package/build/typescript/index.d.ts +4 -0
  98. package/build/typescript/index.d.ts.map +1 -0
  99. package/build/typescript/request-router.d.ts +15 -0
  100. package/build/typescript/request-router.d.ts.map +1 -0
  101. package/build/typescript/shared/magic-module.d.ts +32 -0
  102. package/build/typescript/shared/magic-module.d.ts.map +1 -0
  103. package/build/typescript/shared/strings.d.ts +2 -0
  104. package/build/typescript/shared/strings.d.ts.map +1 -0
  105. package/package.json +52 -0
  106. package/quilt.project.ts +5 -0
  107. package/source/app.ts +217 -0
  108. package/source/constants.ts +5 -0
  109. package/source/env.ts +153 -0
  110. package/source/index.ts +13 -0
  111. package/source/request-router.ts +33 -0
  112. package/source/shared/magic-module.ts +53 -0
  113. package/source/shared/strings.ts +17 -0
  114. package/tsconfig.json +10 -0
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var isValidValue = function isValidValue(x) {
6
+ return x != null && !Number.isNaN(x) && typeof x !== 'boolean';
7
+ };
8
+
9
+ var removeNonPrintingValuesTransformer = function removeNonPrintingValuesTransformer() {
10
+ return {
11
+ onSubstitution: function onSubstitution(substitution) {
12
+ if (Array.isArray(substitution)) {
13
+ return substitution.filter(isValidValue);
14
+ }
15
+ if (isValidValue(substitution)) {
16
+ return substitution;
17
+ }
18
+ return '';
19
+ }
20
+ };
21
+ };
22
+
23
+ exports["default"] = removeNonPrintingValuesTransformer;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Replaces tabs, newlines and spaces with the chosen value when they occur in sequences
7
+ * @param {(String|RegExp)} replaceWhat - the value or pattern that should be replaced
8
+ * @param {*} replaceWith - the replacement value
9
+ * @return {Object} - a TemplateTag transformer
10
+ */
11
+ var replaceResultTransformer = function replaceResultTransformer(replaceWhat, replaceWith) {
12
+ return {
13
+ onEndResult: function onEndResult(endResult) {
14
+ if (replaceWhat == null || replaceWith == null) {
15
+ throw new Error('replaceResultTransformer requires at least 2 arguments.');
16
+ }
17
+ return endResult.replace(replaceWhat, replaceWith);
18
+ }
19
+ };
20
+ };
21
+
22
+ exports["default"] = replaceResultTransformer;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var replaceSubstitutionTransformer = function replaceSubstitutionTransformer(replaceWhat, replaceWith) {
6
+ return {
7
+ onSubstitution: function onSubstitution(substitution, resultSoFar) {
8
+ if (replaceWhat == null || replaceWith == null) {
9
+ throw new Error('replaceSubstitutionTransformer requires at least 2 arguments.');
10
+ }
11
+
12
+ // Do not touch if null or undefined
13
+ if (substitution == null) {
14
+ return substitution;
15
+ } else {
16
+ return substitution.toString().replace(replaceWhat, replaceWith);
17
+ }
18
+ }
19
+ };
20
+ };
21
+
22
+ exports["default"] = replaceSubstitutionTransformer;
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
+ var stripIndentTransformer = require('../stripIndentTransformer/stripIndentTransformer.cjs');
5
+ var inlineArrayTransformer = require('../inlineArrayTransformer/inlineArrayTransformer.cjs');
6
+ var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
7
+ var splitStringTransformer = require('../splitStringTransformer/splitStringTransformer.cjs');
8
+ var replaceSubstitutionTransformer = require('../replaceSubstitutionTransformer/replaceSubstitutionTransformer.cjs');
9
+
10
+ new TemplateTag["default"](splitStringTransformer["default"]('\n'), inlineArrayTransformer["default"], stripIndentTransformer["default"], trimResultTransformer["default"], replaceSubstitutionTransformer["default"](/&/g, '&amp;'), replaceSubstitutionTransformer["default"](/</g, '&lt;'), replaceSubstitutionTransformer["default"](/>/g, '&gt;'), replaceSubstitutionTransformer["default"](/"/g, '&quot;'), replaceSubstitutionTransformer["default"](/'/g, '&#x27;'), replaceSubstitutionTransformer["default"](/`/g, '&#x60;'));
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var splitStringTransformer = function splitStringTransformer(splitBy) {
6
+ return {
7
+ onSubstitution: function onSubstitution(substitution, resultSoFar) {
8
+ if (splitBy != null && typeof splitBy === 'string') {
9
+ if (typeof substitution === 'string' && substitution.includes(splitBy)) {
10
+ substitution = substitution.split(splitBy);
11
+ }
12
+ } else {
13
+ throw new Error('You need to specify a string character to split by.');
14
+ }
15
+ return substitution;
16
+ }
17
+ };
18
+ };
19
+
20
+ exports["default"] = splitStringTransformer;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
6
+ var stripIndentTransformer = require('../stripIndentTransformer/stripIndentTransformer.cjs');
7
+ var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
8
+
9
+ var stripIndent = new TemplateTag["default"](stripIndentTransformer["default"], trimResultTransformer["default"]);
10
+
11
+ exports["default"] = stripIndent;
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
6
+
7
+ /**
8
+ * strips indentation from a template literal
9
+ * @param {String} type = 'initial' - whether to remove all indentation or just leading indentation. can be 'all' or 'initial'
10
+ * @return {Object} - a TemplateTag transformer
11
+ */
12
+ var stripIndentTransformer = function stripIndentTransformer() {
13
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'initial';
14
+ return {
15
+ onEndResult: function onEndResult(endResult) {
16
+ if (type === 'initial') {
17
+ // remove the shortest leading indentation from each line
18
+ var match = endResult.match(/^[^\S\n]*(?=\S)/gm);
19
+ var indent = match && Math.min.apply(Math, _toConsumableArray(match.map(function (el) {
20
+ return el.length;
21
+ })));
22
+ if (indent) {
23
+ var regexp = new RegExp('^.{' + indent + '}', 'gm');
24
+ return endResult.replace(regexp, '');
25
+ }
26
+ return endResult;
27
+ }
28
+ if (type === 'all') {
29
+ // remove all indentation from each line
30
+ return endResult.replace(/^[^\S\n]+/gm, '');
31
+ }
32
+ throw new Error('Unknown type: ' + type);
33
+ }
34
+ };
35
+ };
36
+
37
+ exports["default"] = stripIndentTransformer;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var TemplateTag = require('../TemplateTag/TemplateTag.cjs');
4
+ var stripIndentTransformer = require('../stripIndentTransformer/stripIndentTransformer.cjs');
5
+ var trimResultTransformer = require('../trimResultTransformer/trimResultTransformer.cjs');
6
+
7
+ new TemplateTag["default"](stripIndentTransformer["default"]('all'), trimResultTransformer["default"]);
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * TemplateTag transformer that trims whitespace on the end result of a tagged template
7
+ * @param {String} side = '' - The side of the string to trim. Can be 'start' or 'end' (alternatively 'left' or 'right')
8
+ * @return {Object} - a TemplateTag transformer
9
+ */
10
+ var trimResultTransformer = function trimResultTransformer() {
11
+ var side = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
12
+ return {
13
+ onEndResult: function onEndResult(endResult) {
14
+ if (side === '') {
15
+ return endResult.trim();
16
+ }
17
+
18
+ side = side.toLowerCase();
19
+
20
+ if (side === 'start' || side === 'left') {
21
+ return endResult.replace(/^\s*/, '');
22
+ }
23
+
24
+ if (side === 'end' || side === 'right') {
25
+ return endResult.replace(/\s*$/, '');
26
+ }
27
+
28
+ throw new Error('Side not supported: ' + side);
29
+ }
30
+ };
31
+ };
32
+
33
+ exports["default"] = trimResultTransformer;
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var constants = require('./constants.cjs');
4
+ var magicModule = require('./shared/magic-module.cjs');
5
+ var strings = require('./shared/strings.cjs');
6
+
7
+ function magicModuleRequestRouterEntry({
8
+ host,
9
+ port
10
+ } = {}) {
11
+ return magicModule.createMagicModuleEntryPlugin({
12
+ name: '@quilted/request-router',
13
+ sideEffects: true,
14
+ async source() {
15
+ const initialContent = strings.multiline`
16
+ import requestRouter from ${JSON.stringify(constants.MAGIC_MODULE_REQUEST_ROUTER)};
17
+
18
+ import {createHttpServer} from '@quilted/quilt/request-router/node';
19
+
20
+ const port = ${port ?? 'Number.parseInt(process.env.PORT, 10)'};
21
+ const host = ${host ? JSON.stringify(host) : 'process.env.HOST'};
22
+
23
+ createHttpServer(requestRouter).listen(port, host);
24
+ `;
25
+ return initialContent;
26
+ }
27
+ });
28
+ }
29
+
30
+ exports.magicModuleRequestRouterEntry = magicModuleRequestRouterEntry;
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var constants = require('../constants.cjs');
4
+
5
+ const VIRTUAL_MODULE_PREFIX = '\0';
6
+ const VIRTUAL_MODULE_POSTFIX = '/module.js';
7
+ function createMagicModulePlugin({
8
+ name,
9
+ module,
10
+ alias = `${VIRTUAL_MODULE_PREFIX}${module}${VIRTUAL_MODULE_POSTFIX}`,
11
+ source: getSource,
12
+ sideEffects = false
13
+ }) {
14
+ return {
15
+ name,
16
+ resolveId(id) {
17
+ if (id !== module) return null;
18
+ return {
19
+ id: alias,
20
+ moduleSideEffects: sideEffects ? 'no-treeshake' : undefined
21
+ };
22
+ },
23
+ load: getSource ? async function load(source) {
24
+ if (source !== alias) return null;
25
+ const code = await getSource.call(this);
26
+ return {
27
+ code,
28
+ moduleSideEffects: sideEffects ? 'no-treeshake' : undefined
29
+ };
30
+ } : undefined
31
+ };
32
+ }
33
+ function createMagicModuleEntryPlugin({
34
+ module = constants.MAGIC_MODULE_ENTRY,
35
+ ...options
36
+ }) {
37
+ return createMagicModulePlugin({
38
+ ...options,
39
+ module
40
+ });
41
+ }
42
+
43
+ exports.createMagicModuleEntryPlugin = createMagicModuleEntryPlugin;
44
+ exports.createMagicModulePlugin = createMagicModulePlugin;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ function multiline(strings, ...values) {
4
+ let result = strings.reduce((combined, string, index) => `${combined}${string}${values[index] ?? ''}`, '');
5
+
6
+ // Inspired by https://github.com/zspecza/common-tags/blob/master/src/stripIndentTransformer/stripIndentTransformer.js#L8
7
+ const match = result.match(/^[^\S\n]*(?=\S)/gm);
8
+ const indent = match && Math.min(...match.map(indent => indent.length));
9
+ if (indent) {
10
+ const regexp = new RegExp(`^.{${indent}}`, 'gm');
11
+ result = result.replace(regexp, '');
12
+ }
13
+ return result.trim();
14
+ }
15
+
16
+ exports.multiline = multiline;
@@ -0,0 +1,130 @@
1
+ import { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.mjs';
2
+ import { magicModuleEnv } from './env.mjs';
3
+ import { magicModuleRequestRouterEntry } from './request-router.mjs';
4
+ import { multiline } from './shared/strings.mjs';
5
+ import { createMagicModulePlugin, createMagicModuleEntryPlugin } from './shared/magic-module.mjs';
6
+
7
+ function quiltApp({
8
+ env,
9
+ entry
10
+ } = {}) {
11
+ return {
12
+ name: '@quilted/app',
13
+ options(originalOptions) {
14
+ const newPlugins = [...(Array.isArray(originalOptions.plugins) ? originalOptions.plugins : originalOptions.plugins ? [originalOptions.plugins] : [])];
15
+ const newOptions = {
16
+ ...originalOptions,
17
+ plugins: newPlugins
18
+ };
19
+ if (env) {
20
+ newPlugins.push(typeof env === 'boolean' ? magicModuleEnv() : magicModuleEnv(env));
21
+ }
22
+ if (entry) {
23
+ newPlugins.push(magicModuleAppComponent({
24
+ entry
25
+ }));
26
+ }
27
+ return newOptions;
28
+ }
29
+ };
30
+ }
31
+ function quiltAppBrowser(options = {}) {
32
+ return {
33
+ name: '@quilted/app/browser',
34
+ options(originalOptions) {
35
+ const newPlugins = [...(Array.isArray(originalOptions.plugins) ? originalOptions.plugins : originalOptions.plugins ? [originalOptions.plugins] : [])];
36
+ const newOptions = {
37
+ ...originalOptions,
38
+ plugins: newPlugins
39
+ };
40
+ newPlugins.push(magicModuleAppBrowserEntry(options));
41
+ return newOptions;
42
+ }
43
+ };
44
+ }
45
+ function quiltAppServer(options = {}) {
46
+ return {
47
+ name: '@quilted/app/server',
48
+ options(originalOptions) {
49
+ const newPlugins = [...(Array.isArray(originalOptions.plugins) ? originalOptions.plugins : originalOptions.plugins ? [originalOptions.plugins] : [])];
50
+ const newOptions = {
51
+ ...originalOptions,
52
+ plugins: newPlugins
53
+ };
54
+ newPlugins.push(magicModuleRequestRouterEntry());
55
+ newPlugins.push(magicModuleAppRequestRouter(options));
56
+ return newOptions;
57
+ }
58
+ };
59
+ }
60
+ function magicModuleAppComponent({
61
+ entry
62
+ }) {
63
+ return createMagicModulePlugin({
64
+ name: '@quilted/magic-module/app',
65
+ module: MAGIC_MODULE_APP_COMPONENT,
66
+ alias: entry
67
+ });
68
+ }
69
+ function magicModuleAppRequestRouter({
70
+ entry
71
+ } = {}) {
72
+ return createMagicModulePlugin({
73
+ name: '@quilted/magic-module/app-request-router',
74
+ module: MAGIC_MODULE_REQUEST_ROUTER,
75
+ alias: entry,
76
+ source: entry ? undefined : async function source() {
77
+ return multiline`
78
+ import '@quilted/quilt/globals';
79
+
80
+ import {jsx} from 'react/jsx-runtime';
81
+ import {RequestRouter} from '@quilted/quilt/request-router';
82
+ import {renderToResponse} from '@quilted/quilt/server';
83
+
84
+ import App from ${JSON.stringify(MAGIC_MODULE_APP_COMPONENT)};
85
+ import {BrowserAssets} from ${JSON.stringify(MAGIC_MODULE_BROWSER_ASSETS)};
86
+
87
+ const router = new RequestRouter();
88
+ const assets = new BrowserAssets();
89
+
90
+ // For all GET requests, render our React application.
91
+ router.get(async (request) => {
92
+ const response = await renderToResponse(jsx(App), {
93
+ request,
94
+ assets,
95
+ });
96
+
97
+ return response;
98
+ });
99
+
100
+ export default router;
101
+ `;
102
+ }
103
+ });
104
+ }
105
+ function magicModuleAppBrowserEntry({
106
+ hydrate = true,
107
+ selector = '#app'
108
+ } = {}) {
109
+ return createMagicModuleEntryPlugin({
110
+ name: '@quilted/magic-module/app-browser-entry',
111
+ sideEffects: true,
112
+ async source() {
113
+ const reactRootFunction = hydrate ? 'hydrateRoot' : 'createRoot';
114
+ return multiline`
115
+ import '@quilted/quilt/globals';
116
+
117
+ import {jsx} from 'react/jsx-runtime';
118
+ import {${reactRootFunction}} from 'react-dom/client';
119
+
120
+ import App from ${JSON.stringify(MAGIC_MODULE_APP_COMPONENT)};
121
+
122
+ const element = document.querySelector(${JSON.stringify(selector)});
123
+
124
+ ${hydrate ? `${reactRootFunction}(element, jsx(App));` : `${reactRootFunction}(element).render(jsx(App));`}
125
+ `;
126
+ }
127
+ });
128
+ }
129
+
130
+ export { magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, quiltApp, quiltAppBrowser, quiltAppServer };
@@ -0,0 +1,7 @@
1
+ const MAGIC_MODULE_ENV = 'quilt:module/env';
2
+ const MAGIC_MODULE_ENTRY = 'quilt:module/entry';
3
+ const MAGIC_MODULE_APP_COMPONENT = 'quilt:module/app';
4
+ const MAGIC_MODULE_BROWSER_ASSETS = 'quilt:module/assets';
5
+ const MAGIC_MODULE_REQUEST_ROUTER = 'quilt:module/request-router';
6
+
7
+ export { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY, MAGIC_MODULE_ENV, MAGIC_MODULE_REQUEST_ROUTER };
@@ -0,0 +1,108 @@
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
3
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/TemplateTag/TemplateTag.mjs';
4
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaLists/commaLists.mjs';
5
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsAnd/commaListsAnd.mjs';
6
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/commaListsOr/commaListsOr.mjs';
7
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/html/html.mjs';
8
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/safeHtml/safeHtml.mjs';
9
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLine/oneLine.mjs';
10
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineTrim/oneLineTrim.mjs';
11
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaLists/oneLineCommaLists.mjs';
12
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsOr/oneLineCommaListsOr.mjs';
13
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineCommaListsAnd/oneLineCommaListsAnd.mjs';
14
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/inlineLists/inlineLists.mjs';
15
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/oneLineInlineLists/oneLineInlineLists.mjs';
16
+ import stripIndent from './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndent/stripIndent.mjs';
17
+ import './node_modules/.pnpm/common-tags@1.8.2/node_modules/common-tags/es/stripIndents/stripIndents.mjs';
18
+ import { MAGIC_MODULE_ENV } from './constants.mjs';
19
+ import { createMagicModulePlugin } from './shared/magic-module.mjs';
20
+
21
+ function magicModuleEnv({
22
+ mode,
23
+ dotenv = {
24
+ roots: ['.', 'configuration']
25
+ },
26
+ inline = [],
27
+ runtime = '{}'
28
+ } = {}) {
29
+ return createMagicModulePlugin({
30
+ name: '@quilted/magic-module/env',
31
+ module: MAGIC_MODULE_ENV,
32
+ async source() {
33
+ const inlineEnv = {};
34
+ if (mode) {
35
+ inlineEnv.MODE = mode;
36
+ }
37
+ const loadedEnv = await loadEnv.call(this, {
38
+ mode,
39
+ dotenv
40
+ });
41
+ for (const inlineVariable of inline.sort()) {
42
+ if (inlineVariable in inlineEnv) continue;
43
+ const value = process.env[inlineVariable] ?? loadedEnv[inlineVariable];
44
+ if (value == null) continue;
45
+ inlineEnv[inlineVariable] = typeof value === 'string' && value[0] === '"' && value[value.length - 1] === '"' ? JSON.parse(value) : value;
46
+ }
47
+ return stripIndent`
48
+ const runtime = (${runtime});
49
+ const inline = JSON.parse(${JSON.stringify(JSON.stringify(inlineEnv))});
50
+
51
+ const Env = new Proxy(
52
+ {},
53
+ {
54
+ get(_, property) {
55
+ return runtime[property] ?? inline[property];
56
+ },
57
+ },
58
+ );
59
+
60
+ export default Env;
61
+ `;
62
+ }
63
+ });
64
+ }
65
+
66
+ // Inspired by https://github.com/vitejs/vite/blob/e0a4d810598d1834933ed437ac5a2168cbbbf2f8/packages/vite/source/node/config.ts#L1050-L1113
67
+ async function loadEnv({
68
+ mode,
69
+ dotenv
70
+ }) {
71
+ const env = {
72
+ ...process.env
73
+ };
74
+ if (dotenv !== false) {
75
+ const {
76
+ parse
77
+ } = await import('dotenv');
78
+ let files = dotenv.files;
79
+ if (files == null) {
80
+ const testFiles = [
81
+ // default file
82
+ `.env`,
83
+ // local file
84
+ `.env.local`];
85
+ if (mode) {
86
+ testFiles.push(
87
+ // mode file
88
+ `.env.${mode}`,
89
+ // mode local file
90
+ `.env.${mode}.local`);
91
+ }
92
+ files = testFiles.flatMap(file => (dotenv.roots ?? ['.', 'configuration']).map(root => path.resolve(root, file)));
93
+ }
94
+ const envFileResults = await Promise.all(files.map(async file => {
95
+ if (fs.existsSync(file)) {
96
+ this.addWatchFile(file);
97
+ return parse(await fs.promises.readFile(file, 'utf-8'));
98
+ }
99
+ }));
100
+ for (const envFileResult of envFileResults) {
101
+ if (envFileResult == null) continue;
102
+ Object.assign(env, envFileResult);
103
+ }
104
+ }
105
+ return env;
106
+ }
107
+
108
+ export { magicModuleEnv };
@@ -0,0 +1,3 @@
1
+ export { magicModuleEnv } from './env.mjs';
2
+ export { magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, quiltApp, quiltAppBrowser, quiltAppServer } from './app.mjs';
3
+ export { magicModuleRequestRouterEntry } from './request-router.mjs';