Skip to content

generate example with symlink by default#309

Merged
brody2consult merged 5 commits intomasterfrom
brodybits-example-with-symlink-by-default
Apr 8, 2020
Merged

generate example with symlink by default#309
brody2consult merged 5 commits intomasterfrom
brodybits-example-with-symlink-by-default

Conversation

@brody2consult
Copy link
Owner

@brody2consult brody2consult commented Apr 7, 2020

As suggested by @sunnylqm in #232 (resolves #232):

Uses the following command to link the example as the default behavior:

yarn add link:../

From #232: This symlink behavior should enable the user to "directly modify the library code and test [...] in the example project ".

The previous file linkage behavior (yarn add file:../) may be enabled by using the new, deprecated --example-file-linkage option.

No example postinstall workaround script will be added unless the deprecated --example-file-linkage option is used.

Assuming the deprecated --example-file-linkage option is not used, this update will overwrite the example metro.config.js with the following workaround config code, as needed for Metro to work with the symlink:

// metro.config.js
//
// with multiple workarounds for this issue with symlinks:
// https://github.com/facebook/metro/issues/1
//
// with thanks to @johnryan (<https://github.com/johnryan>)
// for the pointers to multiple workaround solutions here:
// https://github.com/facebook/metro/issues/1#issuecomment-541642857
//
// see also this discussion:
// https://github.com/brodybits/create-react-native-module/issues/232

const path = require('path')

module.exports = {
  // workaround for an issue with symlinks encountered starting with
  // metro@0.55 / React Native 0.61
  // (not needed with React Native 0.60 / metro@0.54)
  resolver: {
    extraNodeModules: new Proxy(
      {},
      { get: (_, name) => path.resolve('.', 'node_modules', name) }
    )
  },

  // quick workaround for another issue with symlinks
  watchFolders: ['.', '..']
}

This symlink behavior is more consistent with the new, interactive brodybits/react-native-module-init CLI tool that I made around this one.

Due credit belongs to the following:


Now tested generated example with:

  • native view on React Native 0.62 on Android & iOS
  • native module on React Native 0.62 on Android & iOS
  • native view on react-native-tvos@0.61 on Android, iOS, & tvOS
  • native module on react-native-tvos@0.61 on Android, iOS, & tvOS
  • native view on React Native 0.61 on Android & iOS
  • native module on React Native 0.61 on Android & iOS
  • native view on react-native-tvos@0.60.4-6 on Android, iOS, & tvOS
  • native module on react-native-tvos@0.60.4-6 on Android, iOS, & tvOS
  • native view on React Native 0.60 on Android & iOS
  • native module on React Native 0.60 on Android & iOS

@brody2consult brody2consult self-assigned this Apr 7, 2020
@brody2consult
Copy link
Owner Author

/merge master

Christopher J. Brody and others added 3 commits April 7, 2020 11:17
by the following shell command:

    yarn add link:../

as suggested in #232 by @sunnylqm

fix and update the description of --generate-example option

previous example file linkage behavior (`yarn add file:../`)
may be enabled by using the new --example-file-linkage option
(`exampleFileLinkage: true` in the library API)
which is already deprecated at this point

omit postinstall scripts entry in example package.json unless
the deprecated --example-file-linkage option is used
(with minor console logging updates)

overwrite the example metro.config.js with quick workaround
for an issue with symlinked modules, unless
the deprecated --example-file-linkage option is used
(with thanks to @johnryan for the pointer)

*tested* with React Native 0.60

(known issue with React Native 0.61 & 0.62 at this point)

update the following test cases to test with the deprecated
`exampleFileLinkage: true` setting:

- json-eacces-error.test.js
- json-enoent-error.test.js
- recover-from-missing-package-scripts.test.js
- create-with-example-with-options.test.js
- create-with-example-with-options.test.js

Co-authored-by: Christopher J. Brody <chris.brody+brodybits@gmail.com>
Co-authored-by: Sunny Luo <sunnylqm@qq.com>
(postinstall workaround script)

add the postinstall workaround script *only* if the
deprecated --example-file-linkage option is enabled
and update the test snapshots
@brody2consult brody2consult changed the title example with symlink by default generate example with symlink by default Apr 7, 2020
@brody2consult brody2consult force-pushed the brodybits-example-with-symlink-by-default branch 2 times, most recently from 9e1b6e8 to db24dea Compare April 7, 2020 22:56
@brody2consult
Copy link
Owner Author

/merge brodybits-generate-example-with-symlink-by-default

for an issue with symlinks encountered
starting with metro@0.55 / React Native 0.61
(not needed for React Native 0.60 / metro@0.54)

add and update descriptive comments in example metro.config.js

*tested* generated example with:

- native view on React Native 0.62 on Android & iOS
- native module on React Native 0.62 on Android & iOS
- native view on react-native-tvos@0.61 on Android, iOS, & tvOS
- native module on react-native-tvos@0.61 on Android, iOS, & tvOS
- native view on React Native 0.61 on Android & iOS
- native module on React Native 0.61 on Android & iOS
- native view on react-native-tvos@0.60.4-6 on Android, iOS, & tvOS
- native module on react-native-tvos@0.60.4-6 on Android, iOS, & tvOS
- native view on React Native 0.60 on Android & iOS
- native module on React Native 0.60 on Android & iOS
@brody2consult brody2consult force-pushed the brodybits-example-with-symlink-by-default branch from 7cad734 to 8fcda63 Compare April 8, 2020 02:29
@brody2consult brody2consult marked this pull request as ready for review April 8, 2020 02:39
@brody2consult brody2consult merged commit 11b3cbd into master Apr 8, 2020
@brody2consult brody2consult deleted the brodybits-example-with-symlink-by-default branch April 8, 2020 05:29
@maitrungduc1410
Copy link

Hi @brodybits ,

I use option --generate-example when generate my project, but when I change my native code (Eg: iOS) and re-run using react-native run-ios, I don't see any update.

am I missing something?

Please help, thank you

@maitrungduc1410
Copy link

maitrungduc1410 commented Apr 16, 2020

After a morning deep dive into the problem, I ended up with a simple solution:

  • In your root library run: yarn link
  • In the example project run: yarn link <your_library_name>

After this every changes from library with get effected into example project

Sorry for commenting directly here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use symbol link for example

2 participants