Commit Graph

93 Commits

Author SHA1 Message Date
Zaid Ajaj 4892fa1fd4
[sdk/nodejs] closure serializtion, lookup package.json from current directory up to parent directories ()
# Description

When using closure serialization, we lookup `package.json` inside of the
current working directory `.`. However, if users put their
`package.json` file in a parent directory and their pulumi program in a
child directory, then it can't find `package.json` and fails to create
inline lambdas.

This PR addresses the issue by looking up `package.json` starting from
the current working directory recursively up parent directories until it
finds the closest `package.json` file and uses that as the "root" of the
project from which the dependencies are inferred.

Fixes  

Didn't know how to write an integration test for this since the issue is
using pulumi/aws but locally testing these code changes succeed the
program.

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->

---------

Co-authored-by: Fraser Waters <fraser@pulumi.com>
2023-08-25 17:01:20 +00:00
Robbie McKinstry 9658df87e7
This commit safely replaces empty interfaces with type aliases.
Empty interfaces have no effect, even when they are subtyping
other interfaces. An empty interface is always equivalent to its supertype.
They can be safely replaced with type aliases, which better express
the semantic equivalence between the two types.
2023-05-11 23:10:00 -04:00
Robbie McKinstry 2e40af5687
Eliminate postfix-!!
The non-null assertion operator ("!") has no effect
if applied twice. !! as a postfix operation does nothing.
This commit eliminates usage of that syntactic form.
2023-05-11 00:01:41 -04:00
Robbie McKinstry 6ab4e11209
Remove unncessary nullish chaining operator. 2023-05-10 12:45:01 -04:00
Robbie McKinstry d6fd384e63
Eliminate unnecessary double negations.
This commit removes instances of prefix-!! where the value
would already be coerced into a boolean. It also removes
instances where the "optional chaining" operator (?.)
would suffice.
2023-05-09 18:35:59 -04:00
Robbie McKinstry 42870b5db2
Don't use the `delete` operator.
This commit replaces uses of `delete` with a safer option,
assigning undefined. `delete` has unexpected behavior and can harm perf.
2023-04-28 22:07:35 -04:00
Robbie McKinstry e05a3bd81c
Apply autoformat
This commit applies the Rome autoformatter to the Node SDK.
These changes are automatically produced. To reproduce these
changes, run `make format` from inside sdk/nodejs.
2023-04-28 18:27:10 -04:00
Fraser Waters f8486ee056 Remove support for old NodeJS versions from function serializer 2022-12-11 21:20:06 +00:00
Pelle Johnsen cc4e34586e fix: emit closure requires in global scope 2022-11-29 07:20:09 +00:00
Kyle Pitzen 5cfad4a909 fix: Allows for parallel pulumi programs to run in the node runtime 2022-10-13 07:15:25 -04:00
Robbie McKinstry e978311216
Enable ESModule interoperability 2022-09-20 10:34:00 -04:00
Anton Tayanovskyy 301d918e25
Make sure import pulumi/pulumi does not necessarily import typescript () 2022-07-22 09:30:54 -04:00
Daniel Bradley 350274c996
Tidy Nodejs SDK imports ()
* Remove unused nodejs SDK imports

Quick audit to find all unused imports in files

- Remove unused `protobufjs` dependency - we use `google-protobuf` and `@grpc/grpc-js`.

* Eliminate additional unused code
2022-05-30 09:31:28 +01:00
Daniel Bradley f9c29df088
Fix eager loading of inflight context ()
Load and cache on first use
2022-05-23 16:02:27 +01:00
Daniel Bradley 09fb3a003d
Delay loading of V8 inspector session ()
Remove start of loading the inspector session as a side-effect of importing the module

Lazy load the inspect session on the first time it's requested for use.

Fixes 
2022-05-18 17:12:34 +01:00
CommanderRoot ab276c43d9
Replace deprecated String.prototype.substr() ()
String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with similar functions which aren't deprecated.
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
2022-03-19 10:04:27 +00:00
Kyle Dixler c8280936dc
JavaScript fnSerialization match package.json exports ()
* Added support for complying with nodejs package.json exports field if provided.

Co-authored-by: Kyle Dixler <kyle@pulumi.com>
Co-authored-by: Ian Wahbe <ian@wahbe.com>
2022-02-08 10:22:56 -08:00
Anton Tayanovskyy 08df93f33e
Work around node SDK tsc failure () 2022-01-04 14:53:41 -05:00
Liam White 6e3e17ef28
Enable workaround for Yarn workspaces for inline functions ()
See https://github.com/pulumi/pulumi/issues/2661\#issuecomment-939531284 for context.

Bascially, yarn workspaces rely on symlinks for monorepo-local packages.

I think this also resolves https://github.com/pulumi/pulumi/issues/2980

Signed-off-by: Liam White <liam@tetrate.io>
2021-10-25 10:13:09 -07:00
Horace Lee a92a005d68
Use ESlint instead of TSlint ()
Migrated TSlint configs to ESlint ones using [tslint-to-eslint-config](https://github.com/typescript-eslint/tslint-to-eslint-config) tool, and refined the configs to better match the current coding style.

Changes:
- [member-delimiter-style](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md#options) that as suggested default for type definition to be  with `semicolon`
- Indentation fixes that is enforced by [eslint-indent](https://eslint.org/docs/rules/indent#options)
- Added dependencies for ESlint with Typescript
- Removed TSlint
2021-08-10 11:31:59 -07:00
PND c6062ea1d5
[sdk/nodejs] Fix a bug in closure serialization. ()
Co-authored-by: Komal <komal@pulumi.com>
Co-authored-by: Luke Hoban <luke@pulumi.com>
2021-07-15 18:20:09 -07:00
stack72 5679496127 [deps] Ensuring pulumi/pulumi pkg references pulumi sdk v3.0.0-beta.2 2021-04-14 19:32:18 +01:00
Evan Boyle fd9f2710b6
Revert "[sdk/nodejs] Add multiple VM contexts support to closure serialization ()" ()
This reverts commit ee2f65510b.
2021-04-13 10:27:59 -07:00
Daniel Sokolowski ee2f65510b
[sdk/nodejs] Add multiple VM contexts support to closure serialization () 2021-04-12 09:13:47 -07:00
Matt Weathers aed070c8e6 Be resilient to 3rd party libraries placing a __rest function on the global object. 2021-03-26 21:23:48 -05:00
jakzo e78dea4979
serialize default parameters () 2021-02-25 21:21:10 -08:00
Luke Hoban 1ef2f10543
Allow `serializeFunction` to capture secrets ()
Adds an opt-in `allowSecrets` flag to `serializeFunction` to allow it to capture secrets.  If passed, `serializeFunction` will now report back whether it captured any secrets.  This information can be used by callers to wrap the resulting text in a Secret value.

Fixes .
2020-12-31 09:37:25 +11:00
Justin Van Patten 9abcca345a
Mark internal APIs `@internal` to filter from API docs ()
Also:

 - Cleaned up existing tags so they're consistently at the bottom of doc comments where they should be
 - Cleaned up some unused imports while I was taking a pass over the files
 - Marked one function `@deprecated` that should be deprecated
2020-01-26 09:06:35 -08:00
CyrusNajmabadi e019e12469
Perform our closure tree-shaking when the code contains element accesses, not just property accesses () 2019-10-02 23:34:09 -07:00
CyrusNajmabadi 7bdd590586
Add deprecation warnings. () 2019-07-30 15:51:44 -07:00
CyrusNajmabadi 3639d1e998
Serialized function parameter count. () 2019-05-20 22:19:22 -04:00
Matt Ellis 825a461b2e Fix a SxS issue with `isSecret`
Because of our Proxy types, every output will return something when
you call `.isSecret` on it. However, if you call it on an output from
a version of `@pulumi/pulumi` which did not support secrets, the thing
you will get back is not undefined but rather an `Output` which wraps
undefined.

Because of this, care must be taken when reading this property and so
a small helper is introduced and used in places we care about.
2019-05-13 15:45:08 -07:00
Matt Ellis 1af821db9c Don't capture secret outputs in closures.
Until  is addressed, we will just disallow capturing secret
outputs when we serialize closures.
2019-05-13 15:45:08 -07:00
CyrusNajmabadi 42812f9b28
Work around a legal code pattern that previous versions of TypeScript complain about. () 2019-04-08 11:21:01 -07:00
CyrusNajmabadi 44150b1fe5
Be resilient to 3rd party libraries placing an __awaiter function on the global object. () 2019-03-28 11:22:34 -07:00
CyrusNajmabadi 906488c7d0
Fix issue where we could not serialize an arrow-function with a deconstructed parameter. () 2019-03-22 16:48:38 -07:00
CyrusNajmabadi be1c3eb05b
Add support for serializing bigints () 2019-03-22 15:33:37 -07:00
CyrusNajmabadi 3bb8759b23
Implement rtti checks more consistently () 2019-02-28 14:56:35 -08:00
CyrusNajmabadi 3d1df982de
Incorrect closure serialization when object referenced through different functions. () 2019-02-28 11:11:43 -08:00
CyrusNajmabadi aa3c6d0ba6
Converting an Output to a string or JSON now produces a warning . () 2019-02-27 16:00:54 -08:00
CyrusNajmabadi 0d2d1eb61a
Rolling back toString/toJSON change ()
* Revert "Make toString and toJSON internal ()"

This reverts commit 7579b84f73.

* Revert "Update error message to point at docs. ()"

This reverts commit 9156c26a2e.

* Revert "Throw on Output.toString and toJSON ()"

This reverts commit c33b4505c0.
2019-02-27 14:53:56 -08:00
CyrusNajmabadi c33b4505c0
Throw on Output.toString and toJSON () 2019-02-26 19:24:21 -08:00
CyrusNajmabadi 57a228c2ab
Fix issue with comments throwing off function/class serialization () 2019-02-08 14:58:24 -08:00
CyrusNajmabadi 5211954f3a
Break out Resource and Output into their own files () 2019-01-31 18:08:17 -08:00
CyrusNajmabadi 901a238fd5
Get closure serialiation working in Node11 ()
* Make v8 primitives async as there is no way to avoid async in node11.

* Simplify API.

* Move processing of well-known globals into the v8 layer.
We'll need this so that we can map from RemoteObjectIds back to these well known values.

* Remove unnecesssary check.

* Cleanup comments and extract helper.

* Introduce helper bridge method for the simple case of making an entry for a string.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Make functions async.  They'll need to be async once we move to the Inspector api.

* Move property access behind helpers so they can move to the Inspector API in the future.

* Only call function when we know we have a Function.  Remove redundant null check.

* Properly serialize certain special JavaScript number values that JSON serialization cannot handle.

* Only marshall across the 'source' and 'flags' for a RegExp when serializing.

* Add a simple test to validate a regex without flags.

* Extract functionality into helper method.

* Add test with complex output scenarios.

* Output serialization needs to avoid recursively trying to serialize a serialized value.

* Introduce indirection for introspecting properties of an object.

* Use our own introspection API for examining an Array.

* Hide direct property access through API indirection.

* Produce values like the v8 Inspector does.

* Compute the module map asynchronously.  Will need that when mapping mirrors instead.

* Cleanup a little code in closure creation.

* Get serialization working on Node11 (except function locations).

* Run tests in the same order on <v11 and >=v11

* Make tests run on multiple versions of node.

* Rename file to make PR simpler to review.

* Cleanup.

* Be more careful with global state.

* Remove commented line.

* Only allow getting a session when on Node11 or above.

* Promisify methods.
2018-11-01 15:46:21 -07:00
CyrusNajmabadi 7efd3ddf05
Cleanup a little code in closure creation. () 2018-10-28 13:02:04 -07:00
CyrusNajmabadi 13d9043771
Produce values like the v8 Inspector does. () 2018-10-28 01:01:48 -07:00
CyrusNajmabadi 1d7f35352d
Properly serialize certain special JavaScript number values that JSON serialization cannot handle. () 2018-10-26 23:46:57 -07:00
Sean Gillespie ae1a2e8b7e
Fail closure serialization in Node 11 ()
* Fail closure serialization in Node 11

Node 11 changed many of the intrinsics that we depend upon for closure
serialization, so until we fix the underlying issues this commit lazily
fails if a closure is serialized when running on Node 11.

* CR feedback
2018-10-25 10:55:47 -07:00
CyrusNajmabadi 19a313b628
Do not analyze user source code for required packages. We'll analyze their project.json for that. () 2018-10-18 11:21:47 -07:00