| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,7 +43,7 @@ const { | |||
| 43 | 43 | rekeySourceMap | |
| 44 | 44 | } = require('internal/source_map/source_map_cache'); | |
| 45 | 45 | const { pathToFileURL, fileURLToPath, URL } = require('internal/url'); | |
| 46 | - const { deprecate } = require('internal/util'); | ||
| 46 | + const { deprecate, emitExperimentalWarning } = require('internal/util'); | ||
| 47 | 47 | const vm = require('vm'); | |
| 48 | 48 | const assert = require('internal/assert'); | |
| 49 | 49 | const fs = require('fs'); | |
@@ -584,17 +584,21 @@ function resolveExportsTarget(pkgPath, target, subpath, basePath, mappingKey) { | |||
| 584 | 584 | if (experimentalConditionalExports && | |
| 585 | 585 | ObjectPrototypeHasOwnProperty(target, 'require')) { | |
| 586 | 586 | try { | |
| 587 | - return resolveExportsTarget(pkgPath, target.require, subpath, | ||
| 588 | - basePath, mappingKey); | ||
| 587 | + const result = resolveExportsTarget(pkgPath, target.require, subpath, | ||
| 588 | + basePath, mappingKey); | ||
| 589 | + emitExperimentalWarning('Conditional exports'); | ||
| 590 | + return result; | ||
| 589 | 591 | } catch (e) { | |
| 590 | 592 | if (e.code !== 'MODULE_NOT_FOUND') throw e; | |
| 591 | 593 | } | |
| 592 | 594 | } | |
| 593 | 595 | if (experimentalConditionalExports && | |
| 594 | 596 | ObjectPrototypeHasOwnProperty(target, 'node')) { | |
| 595 | 597 | try { | |
| 596 | - return resolveExportsTarget(pkgPath, target.node, subpath, | ||
| 597 | - basePath, mappingKey); | ||
| 598 | + const result = resolveExportsTarget(pkgPath, target.node, subpath, | ||
| 599 | + basePath, mappingKey); | ||
| 600 | + emitExperimentalWarning('Conditional exports'); | ||
| 601 | + return result; | ||
| 598 | 602 | } catch (e) { | |
| 599 | 603 | if (e.code !== 'MODULE_NOT_FOUND') throw e; | |
| 600 | 604 | } | |
@@ -697,6 +701,7 @@ Module._findPath = function(request, paths, isMain) { | |||
| 697 | 701 | ||
| 698 | 702 | const selfFilename = trySelf(paths, exts, isMain, trailingSlash, request); | |
| 699 | 703 | if (selfFilename) { | |
| 704 | + emitExperimentalWarning('Package name self resolution'); | ||
| 700 | 705 | Module._pathCache[cacheKey] = selfFilename; | |
| 701 | 706 | return selfFilename; | |
| 702 | 707 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ const createDynamicModule = require( | |||
| 22 | 22 | const fs = require('fs'); | |
| 23 | 23 | const { fileURLToPath, URL } = require('url'); | |
| 24 | 24 | const { debuglog } = require('internal/util/debuglog'); | |
| 25 | - const { promisify } = require('internal/util'); | ||
| 25 | + const { promisify, emitExperimentalWarning } = require('internal/util'); | ||
| 26 | 26 | const { | |
| 27 | 27 | ERR_INVALID_URL, | |
| 28 | 28 | ERR_INVALID_URL_SCHEME, | |
@@ -133,6 +133,7 @@ translators.set('builtin', async function builtinStrategy(url) { | |||
| 133 | 133 | ||
| 134 | 134 | // Strategy for loading a JSON file | |
| 135 | 135 | translators.set('json', async function jsonStrategy(url) { | |
| 136 | + emitExperimentalWarning('Importing JSON modules'); | ||
| 136 | 137 | debug(`Translating JSONModule ${url}`); | |
| 137 | 138 | debug(`Loading JSONModule ${url}`); | |
| 138 | 139 | const pathname = url.startsWith('file:') ? fileURLToPath(url) : null; | |
@@ -187,6 +188,7 @@ translators.set('json', async function jsonStrategy(url) { | |||
| 187 | 188 | ||
| 188 | 189 | // Strategy for loading a wasm module | |
| 189 | 190 | translators.set('wasm', async function(url) { | |
| 191 | + emitExperimentalWarning('Importing Web Assembly modules'); | ||
| 190 | 192 | const buffer = await getSource(url); | |
| 191 | 193 | debug(`Translating WASMModule ${url}`); | |
| 192 | 194 | let compiled; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ | |||
| 7 | 7 | #include "util-inl.h" | |
| 8 | 8 | #include "node_contextify.h" | |
| 9 | 9 | #include "node_watchdog.h" | |
| 10 | + #include "node_process.h" | ||
| 10 | 11 | ||
| 11 | 12 | #include <sys/stat.h> // S_IFDIR | |
| 12 | 13 | ||
@@ -962,6 +963,7 @@ Maybe<URL> ResolveExportsTarget(Environment* env, | |||
| 962 | 963 | Maybe<URL> resolved = ResolveExportsTarget(env, pjson_url, | |
| 963 | 964 | conditionalTarget, subpath, pkg_subpath, base, false); | |
| 964 | 965 | if (!resolved.IsNothing()) { | |
| 966 | + ProcessEmitExperimentalWarning(env, "Conditional exports"); | ||
| 965 | 967 | return resolved; | |
| 966 | 968 | } | |
| 967 | 969 | } | |
@@ -1267,6 +1269,7 @@ Maybe<URL> PackageResolve(Environment* env, | |||
| 1267 | 1269 | ||
| 1268 | 1270 | Maybe<URL> self_url = ResolveSelf(env, specifier, base); | |
| 1269 | 1271 | if (self_url.IsJust()) { | |
| 1272 | + ProcessEmitExperimentalWarning(env, "Package name self resolution"); | ||
| 1270 | 1273 | return self_url; | |
| 1271 | 1274 | } | |
| 1272 | 1275 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,8 @@ v8::Maybe<bool> ProcessEmitWarningGeneric(Environment* env, | |||
| 27 | 27 | const char* code = nullptr); | |
| 28 | 28 | ||
| 29 | 29 | v8::Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...); | |
| 30 | + v8::Maybe<bool> ProcessEmitExperimentalWarning(Environment* env, | ||
| 31 | + const char* warning); | ||
| 30 | 32 | v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, | |
| 31 | 33 | const char* warning, | |
| 32 | 34 | const char* deprecation_code); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | #include <cstdarg> | |
| 2 | + #include <set> | ||
| 2 | 3 | ||
| 3 | 4 | #include "env-inl.h" | |
| 4 | 5 | #include "node_process.h" | |
@@ -95,6 +96,21 @@ Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...) { | |||
| 95 | 96 | return ProcessEmitWarningGeneric(env, warning); | |
| 96 | 97 | } | |
| 97 | 98 | ||
| 99 | + | ||
| 100 | + std::set<std::string> experimental_warnings; | ||
| 101 | + | ||
| 102 | + Maybe<bool> ProcessEmitExperimentalWarning(Environment* env, | ||
| 103 | + const char* warning) { | ||
| 104 | + if (experimental_warnings.find(warning) != experimental_warnings.end()) | ||
| 105 | + return Nothing<bool>(); | ||
| 106 | + | ||
| 107 | + experimental_warnings.insert(warning); | ||
| 108 | + std::string message(warning); | ||
| 109 | + message.append( | ||
| 110 | + " is an experimental feature. This feature could change at any time"); | ||
| 111 | + return ProcessEmitWarningGeneric(env, message.c_str(), "ExperimentalWarning"); | ||
| 112 | + } | ||
| 113 | + | ||
| 98 | 114 | Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, | |
| 99 | 115 | const char* warning, | |
| 100 | 116 | const char* deprecation_code) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + /* eslint-disable node-core/require-common-first, node-core/required-modules */ | ||
| 2 | + import fixtures from './fixtures.js'; | ||
| 3 | + | ||
| 4 | + const { | ||
| 5 | + fixturesDir, | ||
| 6 | + path, | ||
| 7 | + readSync, | ||
| 8 | + readKey, | ||
| 9 | + } = fixtures; | ||
| 10 | + | ||
| 11 | + export { | ||
| 12 | + fixturesDir, | ||
| 13 | + path, | ||
| 14 | + readSync, | ||
| 15 | + readKey, | ||
| 16 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | // Flags: --experimental-modules | |
| 2 | 2 | import { mustCall } from '../common/index.mjs'; | |
| 3 | + import { path } from '../common/fixtures.mjs'; | ||
| 3 | 4 | import { ok, deepStrictEqual, strictEqual } from 'assert'; | |
| 5 | + import { spawn } from 'child_process'; | ||
| 4 | 6 | ||
| 5 | 7 | import { requireFixture, importFixture } from '../fixtures/pkgexports.mjs'; | |
| 6 | 8 | import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; | |
@@ -149,3 +151,33 @@ function assertIncludes(actual, expected) { | |||
| 149 | 151 | ok(actual.toString().indexOf(expected) !== -1, | |
| 150 | 152 | `${JSON.stringify(actual)} includes ${JSON.stringify(expected)}`); | |
| 151 | 153 | } | |
| 154 | + | ||
| 155 | + // Test warning message | ||
| 156 | + [ | ||
| 157 | + [ | ||
| 158 | + '--experimental-conditional-exports', | ||
| 159 | + '/es-modules/conditional-exports.js', | ||
| 160 | + 'Conditional exports', | ||
| 161 | + ], | ||
| 162 | + [ | ||
| 163 | + '--experimental-resolve-self', | ||
| 164 | + '/node_modules/pkgexports/resolve-self.js', | ||
| 165 | + 'Package name self resolution', | ||
| 166 | + ], | ||
| 167 | + ].forEach(([flag, file, message]) => { | ||
| 168 | + const child = spawn(process.execPath, [flag, path(file)]); | ||
| 169 | + | ||
| 170 | + let stderr = ''; | ||
| 171 | + child.stderr.setEncoding('utf8'); | ||
| 172 | + child.stderr.on('data', (data) => { | ||
| 173 | + stderr += data; | ||
| 174 | + }); | ||
| 175 | + child.on('close', (code, signal) => { | ||
| 176 | + strictEqual(code, 0); | ||
| 177 | + strictEqual(signal, null); | ||
| 178 | + ok(stderr.toString().includes( | ||
| 179 | + `ExperimentalWarning: ${message} is an experimental feature. ` + | ||
| 180 | + 'This feature could change at any time' | ||
| 181 | + )); | ||
| 182 | + }); | ||
| 183 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,29 @@ | |||
| 1 | 1 | // Flags: --experimental-json-modules | |
| 2 | 2 | import '../common/index.mjs'; | |
| 3 | - import { strictEqual } from 'assert'; | ||
| 3 | + import { path } from '../common/fixtures.mjs'; | ||
| 4 | + import { strictEqual, ok } from 'assert'; | ||
| 5 | + import { spawn } from 'child_process'; | ||
| 4 | 6 | ||
| 5 | 7 | import secret from '../fixtures/experimental.json'; | |
| 6 | 8 | ||
| 7 | 9 | strictEqual(secret.ofLife, 42); | |
| 10 | + | ||
| 11 | + // Test warning message | ||
| 12 | + const child = spawn(process.execPath, [ | ||
| 13 | + '--experimental-json-modules', | ||
| 14 | + path('/es-modules/json-modules.mjs') | ||
| 15 | + ]); | ||
| 16 | + | ||
| 17 | + let stderr = ''; | ||
| 18 | + child.stderr.setEncoding('utf8'); | ||
| 19 | + child.stderr.on('data', (data) => { | ||
| 20 | + stderr += data; | ||
| 21 | + }); | ||
| 22 | + child.on('close', (code, signal) => { | ||
| 23 | + strictEqual(code, 0); | ||
| 24 | + strictEqual(signal, null); | ||
| 25 | + ok(stderr.toString().includes( | ||
| 26 | + 'ExperimentalWarning: Importing JSON modules is an experimental feature. ' + | ||
| 27 | + 'This feature could change at any time' | ||
| 28 | + )); | ||
| 29 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,10 @@ | |||
| 1 | 1 | // Flags: --experimental-wasm-modules | |
| 2 | 2 | import '../common/index.mjs'; | |
| 3 | + import { path } from '../common/fixtures.mjs'; | ||
| 3 | 4 | import { add, addImported } from '../fixtures/es-modules/simple.wasm'; | |
| 4 | 5 | import { state } from '../fixtures/es-modules/wasm-dep.mjs'; | |
| 5 | - import { strictEqual } from 'assert'; | ||
| 6 | + import { strictEqual, ok } from 'assert'; | ||
| 7 | + import { spawn } from 'child_process'; | ||
| 6 | 8 | ||
| 7 | 9 | strictEqual(state, 'WASM Start Executed'); | |
| 8 | 10 | ||
@@ -13,3 +15,23 @@ strictEqual(addImported(0), 42); | |||
| 13 | 15 | strictEqual(state, 'WASM JS Function Executed'); | |
| 14 | 16 | ||
| 15 | 17 | strictEqual(addImported(1), 43); | |
| 18 | + | ||
| 19 | + // Test warning message | ||
| 20 | + const child = spawn(process.execPath, [ | ||
| 21 | + '--experimental-wasm-modules', | ||
| 22 | + path('/es-modules/wasm-modules.mjs') | ||
| 23 | + ]); | ||
| 24 | + | ||
| 25 | + let stderr = ''; | ||
| 26 | + child.stderr.setEncoding('utf8'); | ||
| 27 | + child.stderr.on('data', (data) => { | ||
| 28 | + stderr += data; | ||
| 29 | + }); | ||
| 30 | + child.on('close', (code, signal) => { | ||
| 31 | + strictEqual(code, 0); | ||
| 32 | + strictEqual(signal, null); | ||
| 33 | + ok(stderr.toString().includes( | ||
| 34 | + 'ExperimentalWarning: Importing Web Assembly modules is ' + | ||
| 35 | + 'an experimental feature. This feature could change at any time' | ||
| 36 | + )); | ||
| 37 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + require('pkgexports/condition') | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments